public void FileUpload(HttpContext context)
{
try
{
context.Response.ContentType = "text/html";
string companyname = context.Request.Params["companyname"];
string billno = context.Request.Params["billno"];
string filename = context.Request.Params["filename"];
string name = companyname "_" billno "_" filename;
HttpFileCollection files = HttpContext.Current.Request.Files;
//指定以伺服器上上傳檔案的儲存路徑
string savePath = context.Server.MapPath("~/upload/");
//檢查伺服器是否有此實體路徑,且若不存在則建立
if (!System.IO.Directory.Exists(savePath))
{
System.IO.Directory.CreateDirectory(savePath);
}
savePath = savePath name;//上傳檔案路徑
files[0].SaveAs(savePath);//儲存檔案
context.Response.Write(savePath);
}
catch (Exception ex)
{
context.Response.Write("FileUpload: " ex.Message);
}
}