上传代码:
string fullname = FileUpload1.FileName.ToString(); string url = FileUpload1.PostedFile.FileName.ToString(); string typ = FileUpload1.PostedFile.ContentType.ToString(); string typ2 = fullname.Substring(fullname.LastIndexOf(".")+ 1); int size = FileUpload1.PostedFile.ContentLength; string upload_file = Server.MapPath("./upload/") + Resumeid + "/" + fullname; try { FileUpload1.PostedFile.SaveAs(upload_file); } catch { //error message } 下载代码:
if (File.Exists(filePath))
{ FileInfo file = new FileInfo(filePath); Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); //解决中文乱码 Response.AddHeader("Content-Disposition", "attachment; filename=" + filename.ToString().Trim()); //解决中文文件名乱码 Response.AddHeader("Content-length", file.Length.ToString()); Response.ContentType = "appliction/octet-stream"; Response.WriteFile(file.FullName); Response.End(); } 创建新文件夹代码:
string CreatePath = Server.MapPath("./upload/") + folder_name.toString();
if (!Directory.Exists(CreatePath)) { Directory.CreateDirectory(CreatePath); } |
|
来自: 悟静 > 《.net和asp.net》