File Uploading tips in ASP.NET

Error: Access denied

It is very common experience to every developer when he/she host a file uploader page.  Interestingly developer does not face this error in development PC.

The main reason of this problem is security issue of the host computer. Host pc does not allow write operation of IU or Guest user. But IU and guest user need write access of upload folder in host pc.

the solution if not very standard considering security. follow the below steps,

1.  enable write access of virtual directory of the page using IIS(default value of write access is unchecked )

2. Right write click uploading folder of the site. In the security tab provide write access to Users, Internet Guest Account.

upload_share1

3. Complete

The main disadvantage of this technique is the security. Write access of IU user some time vulnerable. so, alternatively your can use database to store file instead of file system.

Thanks
Khayer
GIS Programmer, CEGIS
Bangladesh

Some important technique in JavaScript

##Some simple JavaScript Technique

##Open Popup with sending a URl get value:

function ItemDetails(pName,id)
{ alert(id);
window.open(pName + "?ID=" + id,"MyWindow","status = 1,height = 400,width = 550,resizable = 1,toolbar=1'")
}

//Open JS Popup from code behind

string str="";
str = str + "window.open('PrintMap.aspx?id=" + id + "','PrintMe','height=520px,width=620px,scrollbars=1,resizable=yes,toolbar=yes')";

str = str + "";
ClientScript.RegisterStartupScript(this.GetType(), "onclick", str);


// below technique is not recommended

string tem;
tem = "Page2.aspx";
Response.Write("script window.open('" + tem + "','_blank','scrollbars=yes,width=400,height=500,resizable=yes') script");

##Page redirection using JS:

//redirect to current page(Not reload)
window.location=location.href;

##Close Popup and reflect chage to parrent page

function closePopup()
{
//window.opener.document.location.reload();
/* OR window.opener.document.location.href='myParentWindow.newpage'; */
//self.close ()
window.opener.document.forms(0).submit();
window.close();
}

##Check is not number value in javascript

function CheckAge(source, arguments)
{ var myVal=arguments.Value;
//alert(myVal);
if(isNaN(myVal) || myVal<19)
{
arguments.IsValid=false;
}
else
arguments.IsValid=true;
}

Use Checkbox in Grid templetefield

we can esily use checkbox into templetefiled in grid control. If you use Mysql, it is better to use field data type as bit. Again you can also use text type where you store value like YES/NO.

Now, please go to the page source view. Add a new template field in the grid like below,

Here check box is not two way binding. you can not use Bind. so you need some care in the time inserting. Write below code in grid view RowUpdating event,

// in grid row updating event
e.NewValues["isZoomToExtent"]= ((CheckBox)GridView1.Rows[GridView1.EditIndex].FindControl("editChkIsZoomToExtent")).Checked;

All is done, you can now enjoy the output

Thanks
Khayer
GIS Programmer, CEGIS
Bangladesh