Code
1 #region 上传文件
2 /// <summary>
3 ///
4 /// </summary>
5 /// <param name="FileUp">上传文件的控件名</param>
6 /// <returns>如果上传成功,返回新文件名,否则返回error</returns>
7 protected string UploadProductsPhoto(FileUpload FileUp)
8 {
9 string fpname = "";
10 if (FileUp.HasFile)
11 {
12 String fileExtension = System.IO.Path.GetExtension(FileUp.FileName).ToLower();
13 if (fileExtension == ".xls")
14 {
15 HttpPostedFile f = FileUp.PostedFile;//这个知道是什么吧
16 string FileName = DateTime.Now.ToString("yyyyMMddhhmmssfff"); //获取一个不重复的文件名
17 string FileOrginName = f.FileName.Substring(f.FileName.LastIndexOf("\\") + 1);//获取文件的原始名
18 if (f.ContentLength > 0)
19 {
20 string postFileName = "";
21 string path = System.Configuration.ConfigurationManager.AppSettings["savepath"].ToString();
22 int pos = f.FileName.LastIndexOf(".") + 1;
23 postFileName = f.FileName.Substring(pos, f.FileName.Length - pos);
24 //this.lb_fjmc.Text = FileOrginName;
25 try
26 {
27 f.SaveAs(path + FileName + "." + postFileName); //存储指定的文件到指定的目录
28 //f.SaveAs(path + FileOrginName); //存储指定的文件到指定的目录
29 }
30 catch (Exception ex)
31 {
32 string errstr = "出错:" + ex.Message + ex.StackTrace;
33 //Response.Redirect("../error.aspx?err=" + errstr.Replace("\n", ""), true);
34 }
35 //double unit = 1024;
36 fpname = FileName + "." + postFileName;
37 }
38 }
39 else
40 {
41 fpname = "error";
42 }
43 }
44 return fpname;
45 }
46 #endregion
1 #region 上传文件
2 /// <summary>
3 ///
4 /// </summary>
5 /// <param name="FileUp">上传文件的控件名</param>
6 /// <returns>如果上传成功,返回新文件名,否则返回error</returns>
7 protected string UploadProductsPhoto(FileUpload FileUp)
8 {
9 string fpname = "";
10 if (FileUp.HasFile)
11 {
12 String fileExtension = System.IO.Path.GetExtension(FileUp.FileName).ToLower();
13 if (fileExtension == ".xls")
14 {
15 HttpPostedFile f = FileUp.PostedFile;//这个知道是什么吧
16 string FileName = DateTime.Now.ToString("yyyyMMddhhmmssfff"); //获取一个不重复的文件名
17 string FileOrginName = f.FileName.Substring(f.FileName.LastIndexOf("\\") + 1);//获取文件的原始名
18 if (f.ContentLength > 0)
19 {
20 string postFileName = "";
21 string path = System.Configuration.ConfigurationManager.AppSettings["savepath"].ToString();
22 int pos = f.FileName.LastIndexOf(".") + 1;
23 postFileName = f.FileName.Substring(pos, f.FileName.Length - pos);
24 //this.lb_fjmc.Text = FileOrginName;
25 try
26 {
27 f.SaveAs(path + FileName + "." + postFileName); //存储指定的文件到指定的目录
28 //f.SaveAs(path + FileOrginName); //存储指定的文件到指定的目录
29 }
30 catch (Exception ex)
31 {
32 string errstr = "出错:" + ex.Message + ex.StackTrace;
33 //Response.Redirect("../error.aspx?err=" + errstr.Replace("\n", ""), true);
34 }
35 //double unit = 1024;
36 fpname = FileName + "." + postFileName;
37 }
38 }
39 else
40 {
41 fpname = "error";
42 }
43 }
44 return fpname;
45 }
46 #endregion