November 10,2005
[ASP.Net]檔案上傳的方法
if( ( File1.PostedFile != null ) && ( File1.PostedFile.ContentLength > 0 ) )
{
string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
string SaveLocation = Server.MapPath("Document") + "\\" + fn;
try
{
File1.PostedFile.SaveAs(SaveLocation);
Response.Write("The file has been uploaded.");
}
catch ( Exception exp )
{
Response.Write("Error: " + exp.Message);
}
}
else
{
Response.Write("Please select a file to upload.");
}
PS: ASP.NET 只允許將 4,096 KB(即 4 MB)以下的小檔案,較大文件有大文件的上傳方式
{
string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
string SaveLocation = Server.MapPath("Document") + "\\" + fn;
try
{
File1.PostedFile.SaveAs(SaveLocation);
Response.Write("The file has been uploaded.");
}
catch ( Exception exp )
{
Response.Write("Error: " + exp.Message);
}
}
else
{
Response.Write("Please select a file to upload.");
}
PS: ASP.NET 只允許將 4,096 KB(即 4 MB)以下的小檔案,較大文件有大文件的上傳方式
引用URL
http://cgi.blog.roodo.com/trackback/705684