12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class EditMenu_Uppic : System.Web.UI.Page
- {
- LYS.UserData1 myud = new LYS.UserData1();
- protected void Page_Load(object sender, EventArgs e)
- {
-
- }
- protected void btnUpfiles_Click(object sender, EventArgs e)
- {
- string fileDir = Request.QueryString["Dir"].ToString();
- string tableName = Request.QueryString["tn"].ToString();
- string SaveFieldName = Request.QueryString["FieldN"].ToString();
- int KeyF = Convert.ToInt32(Request.QueryString["KeyF"].ToString());
- //HttpPostedFile MyPostedfile = this.FileUpload1.PostedFile;
- Literal1.Text =UpfilesPathandToDBA(FileUpload1, fileDir, true, tableName, SaveFieldName, KeyF).ToString();
- //Literal1.Text = myud.Upfiles(MyPostedfile,fileDir,true,tableName,SaveFieldName,KeyF).ToString();
- }
- /// <summary> 上传文件(所有类型,没有限制,以原文件名或者日期为文件名保存) </summary>
- /// <param name="fileupload">WebControls.FileUpload 控件</param>
- /// <param name="Fdir">保存的文件夹</param>
- /// <param name="OldFilenameOrNewFileName">是以原文件名保存还是以日期为文件名保存</param>
- //调用:
- //Literal1.Text = myud.UpfilesPathandToDB(FileUpload1, "upfile", true, "TreeGJK","URL",23).ToString();
- public string UpfilesPathandToDBA(System.Web.UI.WebControls.FileUpload fileupload, string Fdir, Boolean OldFilenameOrNewFileName, string TableName, string SaveFieldName, Int32 KeyID)
- {// OldFilenameOrNewFileName 为True 时,以日期为文件名,否则以原文件名
- HttpPostedFile postedfile = fileupload.PostedFile;
- //if (!Directory.Exists(Server.MapPath(".") + "PIC"))
- //{ Directory.CreateDirectory(Server.MapPath(".") + "PIC"); }
- StringBuilder strmsg = new StringBuilder();
- string UpFilename = System.IO.Path.GetFileName(postedfile.FileName);
- string UpfileExtension = System.IO.Path.GetExtension(postedfile.FileName);
- string Newfilename = DateTime.Now.ToString("yyyyMMddHHmmssffff") + UpfileExtension;
- if (OldFilenameOrNewFileName == true) { UpFilename = Newfilename; }
- if (postedfile.ContentLength > 0)
- {
- if (TableName.Length > 0 && KeyID > 0)
- { myud.UpdateStringFieldValue(TableName, SaveFieldName, UpFilename.ToString(), KeyID); }
- if (Fdir == "")
- { postedfile.SaveAs(HttpContext.Current.Server.MapPath(".") + "\\" + UpFilename); }
- else
- {
- // Response.Write(HttpContext.Current.Server.MapPath("Upfiles"));
- // Response.End();
- postedfile.SaveAs(HttpContext.Current.Server.MapPath("Upfiles") + "\\" + Fdir + "\\" + UpFilename);
- }
- strmsg.AppendFormat("【文件名:" + UpFilename.ToString() + "】");
- strmsg.AppendFormat("<br>【文件大小:" + postedfile.ContentLength.ToString() + "】");
- strmsg.AppendFormat("<br>【文件类型:" + postedfile.ContentType.ToString() + "】");
- return strmsg.ToString();
- }
- else
- { return "请选择欲上传文件"; }
- }
- }
|