Friday, May 16, 2008

File Uploading and Downloading

Uploading
string Location=Directory.GetDirectories(Server.MapPath("Directories"),EmpName)
//Loacation="D:Integerated\\Directories\\benil\"
string filename=Path.GetFileName(uplTheFile.Value);
if(finename=="")
{
return;
}
if(uplTheFile.PostedFile !=null)
{
uplTheFile.PostedFile.SaveAs(Location+ "" + filename);
//string finelname=path.GetFileName(FileUpload1.PostedFile.FileName);
}
*************
Download
public FileInfo file
file=new FileInfo(Server.MapPath("LeaveForm.doc")
if(file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition","attachment;filename=" +file.Name);
Response.ContentType="application/Octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}

No comments: