|
using System;
using System.Configuration;
using System.Web.UI.WebControls;
using System.Security.Principal;
using System.Xml;
using Itools.Encryption;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;
namespace Ashwin.DAL {
/// <summary>
/// Summary description for Util
/// </summary>
public class Util {
//Design users
//adriaanse.a
//allinsmith.w
private static readonly string whoami = "ashwin.k";//For testing - for cop ["westring.bd"]
private const string encKey = "KFn2oZAwJHWFRbSXoaSlYjl5TADpyyt53rowhbVwH/M=";
private const string encVector = "nb2dZEGWnzg8R1GZAuUkUQ==";
private static System.Collections.ICollection appSettings = ConfigurationManager.AppSettings;
private static System.Configuration.ConnectionStringSettingsCollection connStrings = ConfigurationManager.ConnectionStrings;
/// <summary>
/// Returns the username without the domain of the current logged in user.
/// </summary>
/// <param name="User">Current logged in user, example CN\ashwin.k</param>
/// <returns>Returns the username without the domain of the current logged in user. </returns>
public static string GetSimpleUsername(IPrincipal User) {
//setup user array to split username into domain and username
#if DEBUG
return whoami;
#endif
string[] user;
// define which character is seperating fields
char[] splitter = { '\\' };
//perform split
user = User.Identity.Name.Split(splitter);
//check to see if no domain exists for user
if (user.Length < 2) {
return user[0];
} else {
return user[1];
}
}
/// <summary>
/// Method to make sure that user's inputs are not malicious
/// </summary>
/// <param name="text">User's Input</param>
/// <param name="maxLength">Maximum length of input</param>
/// <returns>The cleaned up version of the input</returns>
public static string InputText(string text, int maxLength) {
text = text.Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;
if (text.Length > maxLength)
text = text.Substring(0, maxLength);
text = Regex.Replace(text, "[\\s]{2,}", " "); //two or more spaces
text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n"); //<br>
text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " "); //
text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty); //any other tags
text = text.Replace("'", "''");
return text;
}
/// <summary>
/// Returns true if the user is a member of any role in the list,
/// or any group in the list with the User's domain apppended in front of each individual role name.
/// If the user it not a member of any role false if returned
/// </summary>
/// <param name="usr">User object to check.</param>
/// <param name="roles">Comma Seperated list of role names</param>
/// <returns>True if user is a member of any role otherwise return false.</returns>
public static bool isInAnyRole(IPrincipal usr, string roles) {
//define the splitter
char[] splitter = { ',' };
//get user's domain
string domain = GetUserDomain(usr);
// create an array of roles
string[] roleArray = roles.Split(splitter);
for (int i = 0; i < roleArray.Length; ++i) {
if (usr.IsInRole(roleArray[i]) || usr.IsInRole(domain + '\\' + roleArray[i])) {
return true;
}
}
return false;
}
/// <summary>
///
/// </summary>
/// <param name="User"></param>
/// <returns></returns>
public static string GetUserDomain(IPrincipal User) {
//setup user array to split username into domain and username
string[] user;
// define which character is seperating fields
char[] splitter = { '\\' };
//perform split
user = User.Identity.Name.Split(splitter);
//check to see if no domain exists for user
if (user.Length < 2) {
return "";
} else return user[0];
}
/// <summary>
/// Get the Server name.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public static string GetServerName(HttpContext context) {
string ret;
string port = context.Request.ServerVariables["SERVER_PORT"];
ret = GetConfigValue("ServerName") + ":" + port;
if (port == "80") {
ret = GetConfigValue("ServerName") + context.Request.ApplicationPath;
}
return "http://" + ret;
}
/// <summary>
/// Looks through LDAP groups for a given name and determines if the user is
/// in that LDAP group
/// </summary>
/// <param name="name"></param>
/// <param name="GroupName"></param>
/// <returns></returns>
public static bool IsUserInLDAPGroup(string name, string GroupName) {
try {
XmlDocument doc = new XmlDocument();
doc.Load("http://groupservice.internal.pg.com/GDSGroupService.jrun?op=ismember&accountshortname=" +
name.Replace("-", ".").ToLower() +
"&groupdn=cn=" + GroupName.ToLower() +
",ou=groups,o=world&expand=true");
return bool.Parse(doc.GetElementsByTagName("ismember")[0].InnerText);
} catch {
return false;
}
}
/// <summary>
/// Return a value from the web.config file or the app.config file
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static string GetConfigValue(string name) {
Cryptography crypto = new Cryptography();
string ret;
string temp;
if (AppSettings.GetType().Equals(typeof(System.Configuration.KeyValueConfigurationCollection))) {
temp = ((System.Configuration.KeyValueConfigurationCollection)AppSettings)[name].Value;
} else {
temp = ((System.Collections.Specialized.NameValueCollection)AppSettings)[name];
}
//Find out if we need to decrypt the value.
switch (name) {
case "WebServicePswd":
case "DBPassword":
case "ContentMonitorDBPassword":
temp = crypto.Decrypt(temp, encKey, encVector);
break;
}
ret = temp;
//return the value
return ret;
}
/// <summary>
/// Return Encrypted value for the specified value
/// </summary>
/// <param name="value"></param>
/// <returns>returns encrypted value</returns>
public static string EncryptValue(string value)
{
Cryptography crypto = new Cryptography();
return crypto.Encrypt(value, encKey, encVector);
}
/// <summary>
/// Return Decrypted value for the specified value
/// </summary>
/// <param name="value"></param>
/// <returns>returns decrypted value</returns>
public static string DecryptValue(string value)
{
Cryptography crypto = new Cryptography();
return crypto.Decrypt(value, encKey, encVector);
}
/// <summary>
/// Function to return a valid string representing a date
/// </summary>
/// <param name="sValue"></param>
/// <returns></returns>
public static string GetValidDate(string sValue) {
if (sValue.Length > 0) {
return DateTime.Parse(sValue).ToShortDateString() + " " + DateTime.Parse(sValue).ToShortTimeString();
} else {
return "";
}
}
/// <summary>
/// Return a valid date as a DateTime object
/// </summary>
/// <param name="sValue"></param>
/// <returns></returns>
public static DateTime GetValidDateAsDateTime(string sValue) {
if (sValue.Length > 0) {
return DateTime.Parse(sValue);
} else {
return DateTime.Today;
}
}
/// <summary>
/// Return a valid integer or 0
/// </summary>
/// <param name="sValue"></param>
/// <returns></returns>
public static int GetValidInt(string sValue) {
if (sValue.Length > 0) {
if (sValue == "True") return 1;
if (sValue == "False") return 0;
return Int32.Parse(sValue);
} else {
return 0;
}
}
/// <summary>
/// Return a valid integer or 0
/// </summary>
/// <param name="sValue"></param>
/// <returns></returns>
public static decimal GetValidDecimal(string sValue) {
if (sValue.Length > 0) {
return Decimal.Parse(sValue);
} else {
return 0;
}
}
/// <summary>
/// Returns a valid interger or 0 from a Dropdown list
/// </summary>
/// <param name="cbo"></param>
/// <returns></returns>
public static int GetValidIntForCombo(DropDownList cbo) {
int ret = 0;
if (cbo.SelectedIndex > 0) {
ret = GetValidInt(cbo.SelectedValue);
}
return ret;
}
/// <summary>
/// Gets item values from a list box and returns them in a string array.
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public static string[] GetSelectedItems(ListBox list) {
string items = "";
foreach (ListItem item in list.Items) {
if (item.Selected) {
items += (items.Length > 0 ? "|" : "") + item.Value;
}
}
if (items.Length == 0) {
return null;
}
return items.Split('|');
}
/// <summary>
/// Gets item values from a list box and returns them in a string of comma sepereated values.
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public static string GetSelectedItemsFromList(ListBox list) {
string items = "";
foreach (int index in list.GetSelectedIndices()) {
items += (items.Length > 0 ? "," : "") + list.Items[index].Value;
}
if (items.Length == 0) {
return string.Empty;
}
return items;
}
public static System.Collections.ICollection AppSettings {
get { return appSettings; }
set { appSettings = value; }
}
public static System.Configuration.ConnectionStringSettingsCollection ConnectionStrings {
get { return connStrings; }
set { connStrings = value; }
}
/// <summary>
/// Returns the exception message + stack trace so it can be logged
/// </summary>
/// <param name="ex">exception</param>
/// <returns>text containing message + stack trace</returns>
static public string returnExecptionText(System.Exception ex) {
Exception unhandledException = ex;
StringBuilder error = new StringBuilder();
while (unhandledException != null) {
error.Append("An unhandled exception occurred: " + unhandledException.Message);
error.Append(" StackTrace: ");
error.Append(unhandledException.StackTrace);
unhandledException = unhandledException.InnerException;
}
return error.ToString();
}
/// <summary>
/// Formats the date as 1-JUN-2006
/// </summary>
/// <param name="date">The Date to format</param>
/// <returns></returns>
public static string DisplayedDate(string date) {
string ret = "";
try {
ret = DateTime.Parse(date).ToString("dd-MMM-yyyy");
} catch { }
return ret;
}
/// <summary>
/// converts string array into the integer array
/// </summary>
/// <param name="strArray"></param>
/// <returns></returns>
public static int[] ConvertStringArrayToIntArray(string[] strArray) {
int[] intArray;
intArray = Array.ConvertAll<string, int>(strArray, new Converter<string, int>(ConvertStringToInt));
return intArray;
}
/// <summary>
/// converts integer array into the string array
/// </summary>
/// <param name="intArray"></param>
/// <returns></returns>
public static string[] ConvertIntArrayToStringArray(int[] intArray) {
string[] strArray;
strArray = Array.ConvertAll<int, string>(intArray, new Converter<int, string>(ConvertIntToString));
return strArray;
}
/// <summary>
/// used as predicate to convert the value fron int to string
/// </summary>
/// <param name="intParameter"></param>
/// <returns></returns>
private static string ConvertIntToString(int intParameter) {
return intParameter.ToString();
}
/// <summary>
/// used as predicate to convert the value fron string to int
/// </summary>
/// <param name="strParameter"></param>
/// <returns></returns>
private static int ConvertStringToInt(string strParameter) {
return int.Parse(strParameter);
}
}
}
Exception thrown, Please help.
|
|
|
|
|
Could you sling that into a code block please, and tell us which line the exception is being thrown at as well as what the exception message says.
|
|
|
|
|
No one is going to read this unformatted drivel. Please format any code, as per CP guidelines, and only include what is relevant. And no, not all of this is relevant to your issue.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Enter your code between "code block"
|
|
|
|
|
using System;
using System.Configuration;
using System.Web.UI.WebControls;
using System.Security.Principal;
using System.Xml;
using Itools.Encryption;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;
namespace Ashwin.DAL
{
public class Util
{
private static readonly string whoami = "ashwin.k";
private const string encKey = "KFn2oZAwJHWFRbSXoaSlYjl5TADpyyt53rowhbVwH/M=";
private const string encVector = "nb2dZEGWnzg8R1GZAuUkUQ==";
private static System.Collections.ICollection appSettings = ConfigurationManager.AppSettings;
private static System.Configuration.ConnectionStringSettingsCollection connStrings = ConfigurationManager.ConnectionStrings;
public static string GetSimpleUsername(IPrincipal User)
{
#if DEBUG
return whoami;
#endif
string[] user;
char[] splitter = { '\\' };
user = User.Identity.Name.Split(splitter);
if (user.Length < 2)
{
return user[0];
}
else
{
return user[1];
}
}
public static string InputText(string text, int maxLength)
{
text = text.Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;
if (text.Length > maxLength)
text = text.Substring(0, maxLength);
text = Regex.Replace(text, "[\\s]{2,}", " ");
text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n");
text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " ");
text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty);
text = text.Replace("'", "''");
return text;
}
public static bool isInAnyRole(IPrincipal usr, string roles)
{
char[] splitter = { ',' };
string domain = GetUserDomain(usr);
string[] roleArray = roles.Split(splitter);
for (int i = 0; i < roleArray.Length; ++i)
{
if (usr.IsInRole(roleArray[i]) || usr.IsInRole(domain + '\\' + roleArray[i]))
{
return true;
}
}
return false;
}
public static string GetUserDomain(IPrincipal User)
{
string[] user;
char[] splitter = { '\\' };
user = User.Identity.Name.Split(splitter);
if (user.Length < 2)
{
return "";
}
else return user[0];
}
public static string GetServerName(HttpContext context)
{
string ret;
string port = context.Request.ServerVariables["SERVER_PORT"];
ret = GetConfigValue("ServerName") + ":" + port;
if (port == "80")
{
ret = GetConfigValue("ServerName") + context.Request.ApplicationPath;
}
return "http://" + ret;
}
public static bool IsUserInLDAPGroup(string name, string GroupName)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load("http://groupservice.internal.pg.com/GDSGroupService.jrun?op=ismember&accountshortname=" +
name.Replace("-", ".").ToLower() +
"&groupdn=cn=" + GroupName.ToLower() +
",ou=groups,o=world&expand=true");
return bool.Parse(doc.GetElementsByTagName("ismember")[0].InnerText);
}
catch
{
return false;
}
}
public static string GetConfigValue(string name)
{
Cryptography crypto = new Cryptography();
string ret;
string temp;
if (AppSettings.GetType().Equals(typeof(System.Configuration.KeyValueConfigurationCollection)))
{
temp = ((System.Configuration.KeyValueConfigurationCollection)AppSettings)[name].Value;
}
else
{
temp = ((System.Collections.Specialized.NameValueCollection)AppSettings)[name];
}
switch (name)
{
case "WebServicePswd":
case "DBPassword":
case "ContentMonitorDBPassword":
temp = crypto.Decrypt(temp, encKey, encVector);
break;
}
ret = temp;
return ret;
}
public static string EncryptValue(string value)
{
Cryptography crypto = new Cryptography();
return crypto.Encrypt(value, encKey, encVector);
}
public static string DecryptValue(string value)
{
Cryptography crypto = new Cryptography();
return crypto.Decrypt(value, encKey, encVector);
}
public static string GetValidDate(string sValue)
{
if (sValue.Length > 0)
{
return DateTime.Parse(sValue).ToShortDateString() + " " + DateTime.Parse(sValue).ToShortTimeString();
}
else
{
return "";
}
}
public static DateTime GetValidDateAsDateTime(string sValue)
{
if (sValue.Length > 0)
{
return DateTime.Parse(sValue);
}
else
{
return DateTime.Today;
}
}
public static int GetValidInt(string sValue)
{
if (sValue.Length > 0)
{
if (sValue == "True") return 1;
if (sValue == "False") return 0;
return Int32.Parse(sValue);
}
else
{
return 0;
}
}
public static decimal GetValidDecimal(string sValue)
{
if (sValue.Length > 0)
{
return Decimal.Parse(sValue);
}
else
{
return 0;
}
}
public static int GetValidIntForCombo(DropDownList cbo)
{
int ret = 0;
if (cbo.SelectedIndex > 0)
{
ret = GetValidInt(cbo.SelectedValue);
}
return ret;
}
public static string[] GetSelectedItems(ListBox list)
{
string items = "";
foreach (ListItem item in list.Items)
{
if (item.Selected)
{
items += (items.Length > 0 ? "|" : "") + item.Value;
}
}
if (items.Length == 0)
{
return null;
}
return items.Split('|');
}
public static string GetSelectedItemsFromList(ListBox list)
{
string items = "";
foreach (int index in list.GetSelectedIndices())
{
items += (items.Length > 0 ? "," : "") + list.Items[index].Value;
}
if (items.Length == 0)
{
return string.Empty;
}
return items;
}
public static System.Collections.ICollection AppSettings
{
get { return appSettings; }
set { appSettings = value; }
}
public static System.Configuration.ConnectionStringSettingsCollection ConnectionStrings
{
get { return connStrings; }
set { connStrings = value; }
}
static public string returnExecptionText(System.Exception ex)
{
Exception unhandledException = ex;
StringBuilder error = new StringBuilder();
while (unhandledException != null)
{
error.Append("An unhandled exception occurred: " + unhandledException.Message);
error.Append(" StackTrace: ");
error.Append(unhandledException.StackTrace);
unhandledException = unhandledException.InnerException;
}
return error.ToString();
}
public static string DisplayedDate(string date)
{
string ret = "";
try
{
ret = DateTime.Parse(date).ToString("dd-MMM-yyyy");
}
catch { }
return ret;
}
public static int[] ConvertStringArrayToIntArray(string[] strArray)
{
int[] intArray;
intArray = Array.ConvertAll<string, int>(strArray, new Converter<string, int>(ConvertStringToInt));
return intArray;
}
public static string[] ConvertIntArrayToStringArray(int[] intArray)
{
string[] strArray;
strArray = Array.ConvertAll<int, string>(intArray, new Converter<int, string>(ConvertIntToString));
return strArray;
}
private static string ConvertIntToString(int intParameter)
{
return intParameter.ToString();
}
private static int ConvertStringToInt(string strParameter)
{
return int.Parse(strParameter);
}
}
}
|
|
|
|
|
Why?
You have done nothing to help the OP learn the proper etiquette here. You have also added more useless space to the forum since not all of this code directly pertains to the question.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
I am populating the repeater control on item_databound, i have button on click of that i need to retrieve the data from the repeater and put in hidden field. appreciate help on this.
appreciate code snippet for this. using ASP.net 2.0 code behind is c#.
Thanks,
DB
ashish
|
|
|
|
|
foreach(var item in Repeater.Items)
{
}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
can we display image in ajax editor control?
|
|
|
|
|
Where is Ajax editor control ??
Is it custom made or in ajax toolkit ?
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
it is in ajax toolkit.
i want to just make like orkut scrap replay editor so i can add image in add control.
i hv done all except that image display.
hv u any idea abt this if yes then plz suggest me.
thank's
|
|
|
|
|
|
hi , iam using asp.net with c#
i want to store the other information to database even the user doesnot select the image in file upload control .how to do can you give example which helps me.
the code works fine when the user selects the image , but when user doesnt select the image it gives errror ,but i want to store the other information if user doesnt selects the image
the code is here please correct the code
SqlCommand cmdsave = new SqlCommand("AddBranchProc11", con);
cmdsave.CommandType = CommandType.StoredProcedure;
con.Open();
cmdsave.Parameters.AddWithValue("@BranchId", txtbranchid.Text);
cmdsave.Parameters.AddWithValue("@BranchName", txtBranchname.Text);
cmdsave.Parameters.AddWithValue("@CompanyId", ddlcompanyid1.SelectedItem.Value);
cmdsave.Parameters.AddWithValue("@ContractNo", txtcontractno.Text);
cmdsave.Parameters.AddWithValue("@Region", ddlRegions.SelectedItem.Value);
cmdsave.Parameters.AddWithValue("@City", txtcity.Text);
cmdsave.Parameters.AddWithValue("@Area", txtarea.Text);
cmdsave.Parameters.AddWithValue("@Address", txtaddress.Text);
cmdsave.Parameters.AddWithValue("@StartDate", txtstartdate1.Text);
cmdsave.Parameters.AddWithValue("@EndDate", txtEnd.Text);
cmdsave.Parameters.AddWithValue("@ContractReminder", ddlcontractreminder.SelectedItem.Value);
FileInfo branchinfo = new FileInfo(FileUpload1.PostedFile.FileName.Trim());
byte[]branchcontent=new byte[branchinfo.Length];
FileStream branchstream = branchinfo.OpenRead();
branchstream.Read(branchcontent,0,branchcontent.Length);
branchstream.Close();
cmdsave.Parameters.AddWithValue("@ReminderType", ddlremindertype.SelectedItem.Value);
cmdsave.Parameters.AddWithValue("@BranchPicture",branchcontent);
cmdsave.Parameters.AddWithValue("@Active", x);
if (cmdsave.ExecuteNonQuery()!= 0)
{
Functions.ShowAlertMessage("saved");
con.Close();
}
|
|
|
|
|
hi,
use the code below,
if (FileUpload1.HasFile)
{
FileInfo branchinfo = new FileInfo(FileUpload1.PostedFile.FileName.Trim());
byte[] branchcontent = new byte[branchinfo.Length];
FileStream branchstream = branchinfo.OpenRead();
branchstream.Read(branchcontent, 0, branchcontent.Length);
branchstream.Close();
cmdsave.Parameters.AddWithValue("@BranchPicture", (branchcontent == null ? DBNull.Value : branchcontent));
}
Hope this will help
|
|
|
|
|
I have made some changes in the above reply
if (FileUpload1.HasFile)
{
FileInfo branchinfo = new FileInfo(FileUpload1.PostedFile.FileName.Trim());
byte[] branchcontent = new byte[branchinfo.Length];
FileStream branchstream = branchinfo.OpenRead();
branchstream.Read(branchcontent, 0, branchcontent.Length);
branchstream.Close();
cmdsave.Parameters.AddWithValue("@BranchPicture", (branchcontent == null ? DBNull.Value : branchcontent));
}
else
{
cmdsave.Parameters.AddWithValue("@BranchPicture", DBNull.Value);
}
|
|
|
|
|
hi iam using asp.net with c#
i have written the code to save the image in database.the code works fine when i browse and upload the picture it will save in database , but some times i have no images so i dont want to upload images that time it is giving error , even though my data base field is allow null
error
System.ArgumentException: The path is not of a legal form.
the code is
===========
SqlCommand cmdsave = new SqlCommand("AddBranchProc11", con);
cmdsave.CommandType = CommandType.StoredProcedure;
con.Open();
cmdsave.Parameters.AddWithValue("@BranchId", txtbranchid.Text);
cmdsave.Parameters.AddWithValue("@BranchName", txtBranchname.Text);
cmdsave.Parameters.AddWithValue("@CompanyId", ddlcompanyid1.SelectedItem.Value);
cmdsave.Parameters.AddWithValue("@ContractNo", txtcontractno.Text);
cmdsave.Parameters.AddWithValue("@Region", ddlRegions.SelectedItem.Value);
cmdsave.Parameters.AddWithValue("@City", txtcity.Text);
cmdsave.Parameters.AddWithValue("@Area", txtarea.Text);
cmdsave.Parameters.AddWithValue("@Address", txtaddress.Text);
cmdsave.Parameters.AddWithValue("@StartDate", txtstartdate1.Text);
cmdsave.Parameters.AddWithValue("@EndDate", txtEnd.Text);
cmdsave.Parameters.AddWithValue("@ContractReminder", ddlcontractreminder.SelectedItem.Value); FileInfo branchinfo = new FileInfo(FileUpload1.PostedFile.FileName.Trim());
byte[]branchcontent=new byte[branchinfo.Length];
FileStream branchstream = branchinfo.OpenRead();
branchstream.Read(branchcontent,0,branchcontent.Length);
branchstream.Close();
cmdsave.Parameters.AddWithValue("@ReminderType", ddlremindertype.SelectedItem.Value);
cmdsave.Parameters.AddWithValue("@BranchPicture",branchcontent);
if (cmdsave.ExecuteNonQuery()!= 0)
{
Functions.ShowAlertMessage("saved");
}
i want to save the information without image also , can you correct my code which helps me
|
|
|
|
|
hi,
Use this code below
cmdsave.Parameters.AddWithValue("@BranchPicture", (branchcontent == null ? DBNull.Value : branchcontent));
Hope this will help.
|
|
|
|
|
Why dont you check if file is chosen or not before you do extract file bytes.
There is a property called HasFile which determines if a file is selected.
byte[] branchcontent;
if (FileUpload1.HasFile)
{
FileInfo branchinfo = new FileInfo(FileUpload1.PostedFile.FileName.Trim());
byte[] branchcontent = new byte[branchinfo.Length];
using (FileStream branchstream = branchinfo.OpenRead())
{
branchstream.Read(branchcontent, 0, branchcontent.Length);
branchstream.Close();
}
}
cmdsave.Parameters.AddWithValue("@BranchPicture",branchcontent);
Do like this.
Abhishek Sur
Don't forget to click "Good Answer" if you like this Solution. Visit My Website-->www.abhisheksur.com
|
|
|
|
|
This might not be answer of your question but still I am suggesting because saving whole image in database is no-way a good practice. It will create huge overload on SQL for bringing and saving this much data rapidly.
Instead, you should save those images into one folder in your project and save its relative path like "../images/uploaded/something.jpeg" into varchar field in database. it will save mammoth time while executing.
And while displaying, just bring varchar filed path from database and assign into src field of img
|
|
|
|
|
You should probably check for FileUpload1.HasFile before you set the @ContractReminder param and do all that other stuff. Then do a simple if/then using HasFile and set the value of the param to DBNull.Value if there isn't a file.
|
|
|
|
|
Hi Every1,
I visited a site and found a search bar which is not moving when we scroll down or up the web page .http://www.plastemart.com/plasticnews.asp#[^].this is the link for that page and you can find a search bar on the right lower corner.Please help me to make one similar to that.I really want to know how can we do that in asp.net...
Thanks in advance
|
|
|
|
|
It's a div with top position absolute .
When you view the source code, check this line:
<div style="visibility: visible; position: absolute; left: 19px; top: 445px; vertical-align: top;" id="myChaser11">
All the controls are put inside the div tag and so they have an absolute position against the page. It will always remain 445px below the top of the page.
..Go Green..
|
|
|
|
|
Hi,
I've added some code to my RowDataBound event handler to allow the user to select a row in a GridView. Here's the code:
e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.MyGridView, "Select$" + e.Row.RowIndex);
Nothing special there, it works fine
The trouble is, there's a CheckBox control, a templated one, and I need to set it "read-only" rather than disabled as I don't want it greyed out because it doesn't look great.
I know how to access a templated control and I know how to set a CheckBox control to read-only so I tried the following but it didn't work:
((CheckBox)e.Row.FindControl("MyCheckBox")).Attributes.Add("onclick", "return false;");
I think it's because I've already set the "onclick" attributes for the row but I don't know how to get the control attributes set as well as the row.
Any ideas?
|
|
|
|
|
hey guys i have a image control in my web form. i want to zoom that image when the user clicks the image.
The image is being retrieved from folder . there are two buttons(Next and Previous) to traverse the images and the information about the image name is retrieved from database.
When the first image loads the zooming works fine. but when i click on next or previous the jQuery for the particular images stops working .
According to what i think is the CssClass is being lost for image control. i have tried mentioning
image1.CssClass="magnify" in every function explicitly but does not work
|
|
|
|
|
Do not use URGENT, it is rude. We are here voluntarily to answer questions and what is urgent to you is not to anyone else.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|