Tuesday, March 24, 2009

How to Upload in asp.net

How to Upload in asp.net:

here is the code of upload.aspx.cs:

private string Directory;

protected void Page_Load(object sender, EventArgs e)
{
Directory = Path.Combine(Request.PhysicalApplicationPath, "uploads");

}

protected void Button1_Click(object sender, EventArgs e)
{

}
protected void Button1_Click1(object sender, EventArgs e)
{
if (FileUploader.PostedFile.FileName == "")
{
lblInfo.Text = "No file spefcified";
//lblInfo.Text =

}

else
{
string extension = Path.GetExtension(FileUploader.PostedFile.FileName);
switch (extension.ToLower())
{
case ".doc":
case ".docx":
case ".txt":
break;
default:
lblInfo.Text = "This file type is not supported";
return;
}

string serverFileName = Path.GetFileName(FileUploader.PostedFile.FileName);
string fullUpladPath = Path.Combine(Directory, serverFileName);

//string fullupladpath = Path.Combine(Directory, serverFileName);

try
{
FileUploader.PostedFile.SaveAs(fullUpladPath);
lblInfo.Text = "File" + serverFileName + " uplaod successfully to " + fullUpladPath;
lblInfo.Text = "Server Filename: " + serverFileName;
serverfpath.Text = "Server Path: " + fullUpladPath;

HyperLink11.Text = serverFileName;
HyperLink11.NavigateUrl = "http://www.fob05.co.cc/uploads/" + serverFileName;


}
catch (Exception err)
{
lblInfo.Text = err.Message.ToString();
}
}

}


Powerd by AVARICESOFT.com

No comments:

Post a Comment