Click here to Skip to main content
15,908,776 members

N!dh!sh - Professional Profile



Summary

    Blog RSS
198
Authority
7
Debator
63
Editor
15
Enquirer
17
Organiser
400
Participant
0
Author
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Reputation

Weekly Data. Recent events may not appear immediately. For information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege. The member types column lists member types who gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilver
Bypass spam checks when posting contentsilversilversilversilversilversilvergoldSubEditor, Mentor, Protector, Editor
Store personal files in your account areaplatinumplatinumSubEditor, Editor
Have live hyperlinks in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Have the ability to include a biography in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Edit a Question in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Edit an Answer in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Delete a Question in Q&AYesSubEditor, Protector, Editor
Delete an Answer in Q&AYesSubEditor, Protector, Editor
Report an ArticlesilversilversilversilverSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubEditor, Mentor, Protector, Editor
Edit other members' articlesSubEditor, Protector, Editor
Create an article without requiring moderationplatinumSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending QuestionProtector
Approve/Disapprove a pending AnswerProtector
Report a forum messagesilversilverbronzeProtector, Editor
Approve/Disapprove a pending Forum MessageProtector
Have the ability to send direct emails to members in the forumsProtector
Create a new tagsilversilversilversilver
Modify a tagsilversilversilversilver

Actions with a green tick can be performed by this member.


 
GeneralExport Pin
N!dh!sh13-Nov-12 6:48
N!dh!sh13-Nov-12 6:48 
GeneralGridview Pin
N!dh!sh10-Oct-11 4:57
N!dh!sh10-Oct-11 4:57 
GeneralCode Tips 3 [modified] Pin
N!dh!sh12-Aug-11 3:47
N!dh!sh12-Aug-11 3:47 
GeneralCodeTips 2 [modified] Pin
N!dh!sh4-Jul-11 0:53
N!dh!sh4-Jul-11 0:53 
1) Upload File
2) To restrict usage of backbutton
3) To pass xml data as a parameter of an SP
4) To change actual URL
5) Dropdown list selected index changed event not fired after page validation failure
6)Return multiple values from a popup
7)Javascript to enable a disabled checkbox
8)CommandName, CommandArgument and Text properties of a linkbutton (in gridview)
9)To delete a row in a datatable
10)To find and change properties of a control in master page
11)Hide an image in a gridview column based on another column text
12)Set super admin in web.config
------------------------------------------------------------------------------------------
1)Upload File

a) Add below code in web.config to avoid problems related to uploading files greater than 4MB,
<system.web>
<httpRuntime maxRequestLength="2097151" requestLengthDiskThreshold="2097151"/>
</system.web>

b)Validate file to upload

i)Method 1:

public Boolean ValidateFile()
{
if (fupload.FileName = = string.Empty)
{
lblErrorMessage.Text = "Please select a file to upload";
return false;
}
else if (Convert.ToInt64(fupload.PostedFile.ContentLength) > 5242880)
{
lblErrorMessage.Text = "File size should be less than 5 MB";
return false;
}
else
{
string strExtension = Path.GetExtension(fupload.PostedFile.FileName).ToString().ToUpper();
string[] validfiles = new string[] { ".PNG", ".JPG" };
foreach (string s in validfiles)
{
if (s == strExtension)
return true;
}
return false;
}
}

ii)Method 2:

Add below code in web.config,
<appSettings>
<add key="ValidFiles" value=".TXT,.DOC,.DOCX,.XLS,.PDF,.JPG,.PNG" />
</appSettings>

Add below code in .aspx.cs page,
public Boolean ValidateFile()
{
string strExtension = "," + Path.GetExtension(fupload.PostedFile.FileName).ToString().ToUpper() + ",";
string strValidFiles = ","+ConfigurationManager.AppSettings["ValidFiles"].ToString()+",";
if (strValidFiles.IndexOf(strExtension.Trim().ToUpper()) != -1)
return true;
else
return false;
}

c) Store uploaded file in folder with a unique name

Method 1:

string strGuid = Convert.ToString(Guid.NewGuid());
string strOriginalFilename, strUniqueFilename;
strOriginalFilename = Path.GetFileName(fupload.FileName);
strUniqueFilename = strGuid + "." + Path.GetExtension(fupload.FileName);

fupload.PostedFile.SaveAs(Server.MapPath("~\\UploadedFiles") + "\\" + strUniqueFilename);

Method 2:

string strOriginalFilename, strUniqueFilename;

strOriginalFilename = Path.GetFileName(fupload.FileName);
strUniqueFilename = DateTime.Now.Ticks.ToString() + "_" + Path.GetFileName(fupload.FileName);
fupload.PostedFile.SaveAs(Server.MapPath("~\\UploadedFiles") + "\\" + strUniqueFilename);

d)View uploaded file

protected void lbnFilename_OnClick(object sender, EventArgs e)
{
string strFilePath = Server.MapPath("~//UploadedFiles") + "\\" + hfUniqueFilename.Value;
if (System.IO.File.Exists(strFilePath) == true)
{
Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" + hfFilename.Value);
Response.ContentType = "application/href";
Response.WriteFile(Server.MapPath("~//UploadedFiles") + "\\" + hfUniqueFilename.Value);
Response.Flush();
Response.End();
}
}

e) Delete an uploaded file from the local folder

string strFolderPath = Server.MapPath("~//UploadedFiles ") + "\\" + strUniqueFilename;
if (System.IO.File.Exists(strFolderPath))
System.IO.File.Delete(strFolderPath);
----------------------------------------------------------------------------------------
2)To restrict usage of backbutton

<script type="text/javascript">
function noBack(){window.history.forward()}
noBack();
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack()}
window.onunload=function(){void(0)}
</script>
----------------------------------------------------------------------------------------
3)To pass xml data as a parameter of an SP
Step 1:

Create a datatable with needed columns and add it to a dataset and add its contents to a string
string[] strHoliday=new string[1];
DataTable dt = new DataTable();
dt.Columns.Add("DocID");
dt.Columns.Add("FromDate");
dt.Columns.Add("ToDate");

DataRow dr;

for(int i=0;i<lbxHolidays.Items.Count;i++)
{
dr = dt.NewRow();

strHoliday = lbxHolidays.Items[i].ToString().Split(new string[] { "to" }, StringSplitOptions.None);
dr["DocID"] = hfSelectedID.Value;
dr["FromDate"] = strHoliday[0];
dr["ToDate"] = strHoliday[1];
dt.Rows.Add(dr);
}
DataSet ds = new DataSet();
ds.Tables.Add(dt);
string strXmlHolidayList = ds.GetXml();
(pass strXmlHolidayList as parameter of SP)
Step 2: Insert XML datas to SQL table
@HolidayList VARCHAR(MAX)=null,
@idoc INT=null
AS
BEGIN
EXEC sp_xml_preparedocument @idoc OUTPUT, @HolidayList

INSERT INTO Tutorial_InsertXmlData
SELECT * FROM OPENXML (@idoc, '/NewDataSet/Table1',2)
WITH (DocID int,FromDate datetime,ToDate datetime)
-----------------------------------------------------------------------------------------
4)To change actual URL
Step 1:
Add Global Application Class and include below code,
void Application_BeginRequest(object sender, EventArgs e)
{
Rewriter.Process();
}
Step 2:
Add a class Rewriter.cs and include below code
public class Rewriter
{
protected XmlNode _oRules = null;
private const int Id=0;
public Rewriter(string url, int value)
{
HttpContext.Current.Response.Redirect(url);
}

protected Rewriter()
{
}

public string GetSubstitution(string zPath)
{
if (zPath.EndsWith("a")) //here 'a' is the duplicate path and it is given inside response.redirect
return zPath.Replace(zPath, "ImageUpload.aspx?id=1");
if (zPath.EndsWith("b"))
return zPath.Replace(zPath, "FileUpload.aspx?id=1");
return zPath;
}

public static void Process()
{
Rewriter oRewriter = new Rewriter();
string zSubst = oRewriter.GetSubstitution(HttpContext.Current.Request.Path);
if (zSubst.Length > 0)
{
HttpContext.Current.RewritePath(zSubst);
}
}
}
----------------------------------------------------------------------------------------
5) Dropdown list selected index changed event not fired after page validation failed.
Include onchange="Page_BlockSubmit = false;"
----------------------------------------------------------------------------------------
6)Return multiple values from a popup
In .aspx main page,
<script language="javascript" type="text/javascript">
function OpenPersonList()
{
var urlPath = 'Persons.aspx?';
var height = 155;
var width = 400;
var sizestring = 'dialogHeight:' + height + 'px;dialogWidth:' + width + 'px;center:Yes;scroll:No;status:No;edge:Raised;';
var retValue = window.showModalDialog(urlPath, '', sizestring);
var retvalues = new Array();
retvalues = retValue;
if (retvalues != null && retvalues.length >= 1) {
document.getElementById('<%=hfPersonID.ClientID %>').value = retvalues[0];
document.getElementById('<%=hfPersonName.ClientID %>').value = retvalues[1];
return true;
}
else
return false;
}
</script>

In .aspx.cs main page,
protected void btnSearch_Click(object sender, EventArgs e)
{
string[] strName = hfPersonName.Value.Split(',');
string[] strIDs = hfPersonID.Value.Split(',');
for (int i = 0; i < strName.Length; i++)
{
ListItem item = new ListItem(strName[i], strIDs[i]);
if (lbxSelectedPersons.Items.Contains(item) == false)
{
lbxSelectedPersons.Items.Add(item);
}
else
MessageBox.Show("Designtaed Person is already added to the list.");
}
hfPersonName.Value = "";
hfPersonID.Value = "";
}

In .aspx of popup page,
<script language="javascript" type="text/javascript">
function handleActionPopUp(id, name)
{
if (form1.hfAction.value == "Y")
{
var retvalues = new Array();
retvalues[0] = document.getElementById('hfPersonID').value;
retvalues[1] = document.getElementById('hfPersonName').value;
window.returnValue = retvalues;
window.close();
}
}
</script>

<body onload="handleActionPopUp(0,0);">

In .aspx.cs of popup page,protected void btnSelectClose_Click(object sender, EventArgs e)
{
string strIDs = "", strNames = "";
for (int i = 0; i < gvPersons.Rows.Count; i++)
{
CheckBox cbox = gvPersons.Rows[i].FindControl("chkSelect") as CheckBox;

if (cbox.Checked)
{
strIDs += (gvPersons.Rows[i].Cells[1].Text + ",");
strNames += (gvPersons.Rows[i].Cells[2].Text + ",");
}
}
if (strNames.Length > 0)
{
strNames = strNames.Substring(0, strNames.Length - 1);//to remove last comma
strIDs = strIDs.Substring(0, strIDs.Length - 1);
hfPersonName.Value = strNames;
hfPersonID.Value = strIDs;
hfAction.Value = "Y";
}
else
Page.ClientScript.RegisterStartupScript(this.GetType(),"alert","alert('Please select atleast one person to be added.')",true);
}
------------------------------------------------------------------------------------------
7)Javascript to enable a disabled checkbox
function ChkEnabled()
{
var a = document.getElementById('<%=CheckBox1.ClientID %>');
a.disabled = false;
if(a.parentElement.tagName == 'SPAN' && a.parentElement.disabled == true)
a.parentElement.disabled = false;
}
------------------------------------------------------------------------------------------
8)CommandName, CommandArgument and Text properties of a linkbutton (in gridview)

In .aspx page,
<ItemTemplate>
<asp:LinkButton ID="lbtnAttachments" runat="server" CommandArgument='<%#Eval("UpdatedOn") %>' CommandName='<%#Eval("UniqueFilename") %>' Text='<%#Eval("OriginalFilename") %>'
OnClick="lbtnAttachments_Click"></asp:LinkButton>

</ItemTemplate>

In .aspx.cs page,
protected void lbtnAttachments_Click(object sender, EventArgs e)
{
LinkButton obj = (LinkButton)sender;
string x = obj.CommandName.ToString();
string y = obj.CommandArgument.ToString();
}
------------------------------------------------------------------------------------------
9)To delete a row in a datatable
for (int i = 0; i < dt.Rows.Count; i++)
{
if (Convert.ToString(dt.Rows[i]["ID"].ToString()) == "3") {
dt.Rows[i].Delete();
dt.AcceptChanges();
}
}
------------------------------------------------------------------------------------------
10)To find and change properties of a control in master page
In child page, include below code,

In Page_Load,
Button objMPButton = (Button)FindControlRecursive(this, "btnMapProcess");
if (objMPButton != null)
objMPButton.CssClass = "TConfigSelected";

And add below function,
public Control FindControlRecursive(Control Root, string Id)
{
if (Root.ID == Id)
return Root;
foreach (Control Ctl in Root.Controls)
{
Control FoundCtl = FindControlRecursive(Ctl, Id);
if (FoundCtl != null)
return FoundCtl;
}
return null;
}
--------------------------------------------------------------------------------------------
11)Hide an image in a gridview column based on another column text
protected void gv_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = (DataRowView)e.Row.DataItem;
string strPriority = drv["ColumnName"].ToString();
Image img = (Image)e.Row.FindControl("imgName");
if(strPriority= ="a")
img.visible=false;
}
}
--------------------------------------------------------------------------------------------
12)Set super admin in web.config

In web.config,
<appSettings>
<add key="SuperAdminName" value="n"/>
<add key="SuperAdminPassword" value="nc"/>
</appSettings>

In master.aspx,
string strSuperAdminName = ConfigurationManager.AppSettings["SuperAdminName"].ToString();
string strSuperAdminPassword = ConfigurationManager.AppSettings["SuperAdminPassword"].ToString();
if(Session["Name"]= =strSuperAdminName && Session["Password"] = = strSuperAdminPassword )
{
}
--------------------------------------------------------------------------------------------

modified on Wednesday, August 10, 2011 5:45 AM


modified 11-Oct-11 3:17am.

GeneralResize uploaded image [modified] Pin
N!dh!sh1-Jul-11 0:40
N!dh!sh1-Jul-11 0:40 
GeneralUseful Links [modified] Pin
N!dh!sh30-May-11 21:19
N!dh!sh30-May-11 21:19 
GeneralCode Tips [modified] Pin
N!dh!sh29-May-11 21:23
N!dh!sh29-May-11 21:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.