分享

asp.net 上传/下载/新建文件夹

 悟静 2013-03-03
上传代码:
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);
            }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多