1.页面添加upload.aspx:
文件上传:<asp:FileUpload ID="FileUpload1" name="idFile" runat="server" onchange="document.getElementById('img1').src= window.URL.createObjectURL(document.getElementById('FileUpload1').files[0]);" />
图片展示:<asp:Image ID="img1" runat="server" />
选择图片可自动展示出来
2.cs上传
if (FileUpload1.HasFile)
{
string fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString();//年月
string ImgName = ImgUpload.FileName;
string ImgExtention = System.IO.Path.GetExtension(ImgName);
int ImgSize = ImgUpload.PostedFile.ContentLength;//此处取得的文件大小的单位是byte
string FilePath = "/upload" + "/" + fileName;
if (System.IO.Directory.Exists(HttpContext.Current.Server.MapPath(Fil