当前位置: 首页>>代码示例>>C#>>正文


C# FileUpload.SaveAs方法代码示例

本文整理汇总了C#中System.Web.UI.WebControls.FileUpload.SaveAs方法的典型用法代码示例。如果您正苦于以下问题:C# FileUpload.SaveAs方法的具体用法?C# FileUpload.SaveAs怎么用?C# FileUpload.SaveAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.UI.WebControls.FileUpload的用法示例。


在下文中一共展示了FileUpload.SaveAs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UploadAttach

        public static Guid UploadAttach(FileUpload fu)
        {
            if (!fu.HasFile || fu.FileName.Length == 0)
            {
                throw new BusinessObjectLogicException("Please select upload file!");
            }

            string path = null;
            try
            {
                string subDirectory = DateTime.Now.ToString("yyyyMM") + Path.DirectorySeparatorChar + DateTime.Now.ToString("dd");
                string directory = System.Configuration.ConfigurationManager.AppSettings["File"] + subDirectory;

                if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);

                string title = Path.GetFileNameWithoutExtension(fu.FileName);
                string ext = Path.GetExtension(fu.FileName);

                path = Path.DirectorySeparatorChar + Path.GetRandomFileName() + ext;

                fu.SaveAs(directory + path);

                Attachment attach = new Attachment(UserHelper.UserName);
                attach.Title = title;
                attach.Path = subDirectory + path;

                new AttachmentBl().AddAttach(attach);

                return attach.UID;
            }
            catch
            {
                throw new BusinessObjectLogicException("File upload fail!");
            }
        }
开发者ID:niceplayer454,项目名称:cfi,代码行数:35,代码来源:FileDUHelper.cs

示例2: UploadFile

        public static string UploadFile(FileUpload fileUpload)
        {
            if (fileUpload == null)
            {
                return string.Empty;
            }

            //Todo: Parameterize media path.
            string uploadDirectory = HttpContext.Current.Server.MapPath("~/Media/Temp");
            if (!System.IO.Directory.Exists(uploadDirectory))
            {
                System.IO.Directory.CreateDirectory(uploadDirectory);
            }

            string id = Guid.NewGuid().ToString();

            if (fileUpload.HasFile)
            {
                id += System.IO.Path.GetExtension(fileUpload.FileName);
                id = System.IO.Path.Combine(uploadDirectory, id);

                fileUpload.SaveAs(id);
            }

            return id;
        }
开发者ID:n4gava,项目名称:mixerp,代码行数:26,代码来源:ImageUpload.cs

示例3: fileupload

        public string fileupload(string name, int id)
        {
            string fileth = "";
            string str = "";
            string fid = name;
            if (File(name))
            {
                if (PdMusic(fid))
                {
                    fid = name.Substring(0, name.LastIndexOf('.')) + "_IMG" + DateTime.Now.ToString("yyyyHHmmssfff") + Path.GetExtension(name);
                }
                fileth = "~/upload/images/" + fid;
                FileInfo filee = new FileInfo(Server.MapPath(fileth));//删除以前的老文件
                if (filee.Exists)
                {
                    filee.Delete();
                }
                FileUpload FiLe = new FileUpload();
                FiLe.SaveAs(Server.MapPath(fileth));
                //判断是修改状态,还是添加状态
                if (id == 0)//添加
                {
                }
                else
                {//修改
                    Daxu.Entity.newlist newlistInfo = new Daxu.Entity.newlist();
                    newlistInfo.cnen = fid;
                    Daxu.BLL.newlistBll.UpdateInewlist(newlistInfo);
                }
                str = fid;

            }
            return str;
            // return "你好!";
        }
开发者ID:dayuhan,项目名称:NETWORK,代码行数:35,代码来源:AjaxClass.cs

示例4: img

 public string img(FileUpload upload)
 {
     string str = "";
     string filename = upload.FileName;
     if (filename.Equals(""))
     {
         MessShowBox.show("图片不能为空", this);
     }
     else
     {
         string type = filename.Substring(filename.LastIndexOf(".") + 1).ToLower();
         if (type == "jpg" || type == "bmp" || type == "gif" || type == "png")
         {
             str = "/public/user_img/" + DateTime.Now.ToString("yyyyMMddhhmmss") + filename;
             if (!File.Exists(filename))
             {
                 upload.SaveAs(MapPath(str));
             }
             else
             {
                 MessShowBox.show("文件已存在,请重命名后再上传", this);
             }
         }
         else
         {
             MessShowBox.show("上传的图片个是不正确,图片格式必须是|jpg|bmp|gif|png", this);
         }
     }
     return str;
 }
开发者ID:kuangzhongwei,项目名称:ad,代码行数:30,代码来源:ad_up_ad.aspx.cs

示例5: UploadFile

        public static string UploadFile(FileUpload fileUpload)
        {
            if (fileUpload == null)
            {
                return string.Empty;
            }

            var tempMediaPath = ConfigurationHelper.GetScrudParameter("TempMediaPath");
            var uploadDirectory = HttpContext.Current.Server.MapPath(tempMediaPath);

            if (!Directory.Exists(uploadDirectory))
            {
                Directory.CreateDirectory(uploadDirectory);
            }

            var id = Guid.NewGuid().ToString();

            if (fileUpload.HasFile)
            {
                id += Path.GetExtension(fileUpload.FileName);
                id = Path.Combine(uploadDirectory, id);

                fileUpload.SaveAs(id);
            }

            return id;
        }
开发者ID:neppie,项目名称:mixerp,代码行数:27,代码来源:ImageUpload.cs

示例6: SaveFileToTemp

        private string SaveFileToTemp(string fileName,FileUpload f)
        {
            if (f.FileName.EndsWith("xls"))
            {
                f.SaveAs(TempPath + "\\"+fileName+".xls");
                return TempPath + "\\"+fileName+".xls";
            }
            else if (f.FileName.EndsWith("xlsx"))
            {
                f.SaveAs(TempPath + "\\"+fileName+".xlsx");
                return TempPath + "\\"+fileName+".xlsx";
            }
            else
                return null;


        }
开发者ID:djzblue,项目名称:ExamOnline,代码行数:17,代码来源:ImportExamData.aspx.cs

示例7: FileUpload

        /// <summary>
        /// 1:上傳檔案格式請參考:UI Spec Excel檔案格式。
        /// 2:檢查檔案Size大於0等必要檢查。
        /// 3:上傳檔案到AP_Server端暫存路徑,如有任何異常,則回傳錯誤訊息停止上傳流程。
        /// </summary>
        public ArrayList FileUpload(string s_UploadPath, FileUpload File_Upload, string s_LoginUser)
        {
            try
            {
                #region 宣告變數

                String s_fileExtension = string.Empty;//副檔名
                String s_fileWithoutExtension = string.Empty;//檔名不包含副檔名
                DateTime d_CreateDate = DateTime.Now;
                ArrayList arl_Return = new ArrayList();
                bool b_fileOK = false;

                #endregion

                # region 檢查上傳檔案的路徑與檔案格式

                s_fileExtension = System.IO.Path.GetExtension(File_Upload.FileName).ToLower();//副檔名
                s_fileWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(File_Upload.FileName).ToLower();//檔名

                if (File_Upload.HasFile)
                {
                    String[] allowedExtensions ={ ".xls" };//在此設定允許上傳的檔案格式

                    for (int i = 0; i < allowedExtensions.Length; i++)
                    {
                        if (s_fileExtension == allowedExtensions[i])
                        { b_fileOK = true; }
                    }
                }

                #endregion

                #region 將檔案上傳至AP

                if (b_fileOK == true)
                {
                    //儲存的新檔名=原檔名_登入者_上傳時間.副檔名
                    s_UploadPath += s_fileWithoutExtension + "_" + s_LoginUser + "_" + d_CreateDate.ToString("yyyyMMddHHmmss") + s_fileExtension;
                    File_Upload.SaveAs(s_UploadPath);

                    arl_Return.Add("TRUE");
                    arl_Return.Add(s_UploadPath);
                    arl_Return.Add(d_CreateDate);
                    arl_Return.Add(s_fileWithoutExtension + "_" + s_LoginUser + "_" + d_CreateDate.ToString("yyyyMMddHHmmss") + s_fileExtension);
                }
                else
                {
                    arl_Return.Add("FALSE");
                    arl_Return.Add("路徑" + File_Upload.PostedFile.FileName + "不是正確的檔案");
                }

                #endregion

                return arl_Return;
            }
            catch (Exception ex)
            { throw ex; }
        }
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:63,代码来源:ProcessImportHoliday.cs

示例8: SaveFile

        public static string SaveFile(FileUpload fileUploader, string filename, string directory)
        {
            CheckDirectory(GetServerDirectoryPath(directory));

            string absoluteDirectoryPath = GetAbsoluteDirectoryPath(filename, directory);
            fileUploader.SaveAs(GetServerDirectoryPath(absoluteDirectoryPath));

            return absoluteDirectoryPath;
        }
开发者ID:heyou93,项目名称:GenesisRev,代码行数:9,代码来源:FileHandler.cs

示例9: checkPhoto

        protected bool checkPhoto(FileUpload imgFU,int catagoryid,int itemid)
        {
            System.Drawing.Image img = null;//System.Drawing.Image.FromStream(PhotoFU.PostedFile.InputStream);

            //Image uploadedImage = null;
            if (imgFU.HasFile && imgFU.FileName != string.Empty && imgFU.FileContent.Length > 0)
            {
                if (imgFU.FileContent.Length <= 1024000)
                {
                    try
                    {
                        img = System.Drawing.Image.FromStream(imgFU.PostedFile.InputStream);
                        if (img.RawFormat.Guid == System.Drawing.Imaging.ImageFormat.Jpeg.Guid ||
                            img.RawFormat.Guid == System.Drawing.Imaging.ImageFormat.Png.Guid ||
                            img.RawFormat.Guid == System.Drawing.Imaging.ImageFormat.Gif.Guid)
                        {
                            //replace the old image with new image
                            string filename = itemid + "Photo.jpg";
                            imgFU.SaveAs(Server.MapPath("~/ItemImages/" + catagoryid + "/" + itemid + "/") + filename);

                            string filePath = Server.MapPath("~/ItemImages/" + catagoryid + "/" + itemid + "/") + filename;
                            string newfileMed = itemid + "Photomedium.jpg";
                            string newfileSmall = itemid + "small.jpg";
                            string resizedImageMed = Server.MapPath("~/ItemImages/" + catagoryid + "/" + itemid + "/") + newfileMed;
                            string resizedImageSmall = Server.MapPath("~/ItemImages/" + catagoryid + "/" + itemid + "/") + newfileSmall;
                            System.Drawing.Image img1 = System.Drawing.Image.FromFile(filePath);

                            System.Drawing.Bitmap bmpD = img1 as Bitmap;

                            Bitmap bmpDriverMed = new Bitmap(bmpD, 512, 372);
                            bmpDriverMed.Save(resizedImageMed, System.Drawing.Imaging.ImageFormat.Jpeg);

                            Bitmap bmpDriverSmall = new Bitmap(bmpD, 170, 126);
                            bmpDriverSmall.Save(resizedImageSmall, System.Drawing.Imaging.ImageFormat.Jpeg);

                            return true;
                        }
                        else
                        {
                            lbl_status.Text = "Selected file is not an image";
                            return false;
                        }
                    }
                    catch (Exception ex)
                    {
                        lbl_status.Text = "Selected file is not an image.<br />" + ex.Message;
                        return false;
                    }
                }
                else
                {
                    lbl_status.Text = "File is too Large. only 1mb allowed";
                    return false;
                }
            }
            else return true;
        }
开发者ID:praanasol,项目名称:Project-buddha,代码行数:57,代码来源:EditItem.aspx.cs

示例10: FileUpload

        public ArrayList FileUpload(string s_UploadPath, FileUpload File_Upload, string s_LoginUser)
        {
            #region
            String s_fileExtension = string.Empty;//副檔名

            String s_fileWithoutExtension = string.Empty;//檔名不包含副檔名
            DateTime d_CreateDate = DateTime.Now;
            ArrayList arl_Return = new ArrayList();
            bool b_fileOK = false;

            # region 檢查上傳檔案的路徑與檔案格式


            s_fileExtension = System.IO.Path.GetExtension(File_Upload.FileName).ToLower();//副檔名

            s_fileWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(File_Upload.FileName).ToLower();//檔名

            if (File_Upload.HasFile)
            {
                String[] allowedExtensions ={ ".xls", ".XLS" };//在此設定允許上傳的檔案格式


                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (s_fileExtension == allowedExtensions[i])
                    {
                        b_fileOK = true;
                    }
                }
            }
            #endregion

            #region 將檔案上傳至AP

            if (b_fileOK == true)
            {
                s_UploadPath += s_fileWithoutExtension + "_" + s_LoginUser + "_" + d_CreateDate.ToString("yyyyMMddHHmmss") + s_fileExtension;
                File_Upload.SaveAs(s_UploadPath);

                arl_Return.Add("TRUE");
                arl_Return.Add(s_UploadPath);
                arl_Return.Add(d_CreateDate);
                arl_Return.Add(s_fileWithoutExtension + "_" + s_LoginUser + "_" + d_CreateDate.ToString("yyyyMMddHHmmss") + s_fileExtension);
                arl_Return.Add(s_fileWithoutExtension);
            }
            else
            {
                arl_Return.Add("FALSE");
                arl_Return.Add("上傳檔案不是xls檔");
            }

            #endregion

            return arl_Return;
            #endregion
        }
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:56,代码来源:VDS_STM37_BCO.cs

示例11: FilesUpload

        /// <summary>
        /// 工具方法:上传文件的方法
        /// </summary>
        /// <param name="myFileUpload">上传控件的ID</param>
        /// <param name="allowExtensions">允许上传的扩展文件名类型,如:string[] allowExtensions = { ".doc", ".xls", ".ppt", ".jpg", ".gif" };</param>
        /// <param name="maxLength">允许上传的最大大小,以M为单位</param>
        /// <param name="savePath">保存文件的目录,注意是绝对路径,如:Server.MapPath("~/upload/");</param>
        /// <param name="saveName">保存的文件名,如果是""则以原文件名保存</param>
        public static string FilesUpload(FileUpload myFileUpload, string[] allowExtensions, int maxLength, string savePath, string saveName)
        {
            // 文件格式是否允许上传
            bool fileAllow = false;
            //检查是否有文件案
            if (myFileUpload.HasFile)
            {
                // 检查文件大小, ContentLength获取的是字节,转成M的时候要除以2次1024
                if (myFileUpload.PostedFile.ContentLength / 1024 / 1024 >= maxLength)
                {
                    return String.Format("只能上传小于{0}M的文件!",maxLength);
                }
                //取得上传文件之扩展文件名,并转换成小写字母
                string fileExtension = System.IO.Path.GetExtension(myFileUpload.FileName).ToLower();
                string tmp = "";   // 存储允许上传的文件后缀名
                //检查扩展文件名是否符合限定类型
                for (int i = 0; i < allowExtensions.Length; i++)
                {
                    tmp += i == allowExtensions.Length - 1 ? allowExtensions[i] : allowExtensions[i] + ",";
                    if (fileExtension == allowExtensions[i])
                    {
                        fileAllow = true;
                    }
                }
                if (allowExtensions.Length == 0) { fileAllow = true; }
                if (fileAllow)
                {
                    try
                    {
                        DirectoryInfo di = new DirectoryInfo(Path.GetFullPath(savePath));
                        if (!di.Exists)
                        {
                            di.Create();
                        }

                        string path = savePath + (saveName == "" ? myFileUpload.FileName : saveName);
                        //存储文件到文件夹
                        myFileUpload.SaveAs(path);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
                else
                {
                    return "文件格式不符,可以上传的文件格式为:" + tmp;
                }
            }
            else
            {
                return "请选择要上传的文件!";
            }
            return "";
        }
开发者ID:uwitec,项目名称:web-mvc-logistics,代码行数:63,代码来源:Upload.cs

示例12: UploadFileAndGetFilePath

        private string UploadFileAndGetFilePath(FileUpload fileUpload)
        {
            string folderPath = Server.MapPath("~/Upload");

            IoHelper.ValidateFolderExsistence(folderPath);

            string filePath = folderPath + @"\" + fileUpload.FileName.ToString();

            IoHelper.ValidateFileExsistence(filePath);

            fileUpload.SaveAs(filePath);

            return filePath;
        }
开发者ID:esitefinity,项目名称:Sitefinity-Ecommerce-Product-Upload,代码行数:14,代码来源:CsvUploader.ascx.cs

示例13: SaveImage

 public static string SaveImage(FileUpload Fu, string prefix, string localImagePath)
 {
     if (!Directory.Exists(localImagePath))
         Directory.CreateDirectory(localImagePath);
     string strImage = string.Empty;
     string SavePath = string.Empty;
     //SavePath = GetImagePathWithFileName(3, prefix, localImagePath);
     SavePath = localImagePath;            
     SavePath += '\\' + prefix;
     Fu.SaveAs(SavePath);
     Fu.FileContent.Dispose();
     strImage = SavePath;
     //Fu.PostedFile.ContentLength
     return strImage;
 }
开发者ID:electrono,项目名称:veg-web,代码行数:15,代码来源:PictureManager.cs

示例14: getImage

 private string getImage(FileUpload fa, string oldFile)
 {
     if (fa.HasFile)
     {
         string file = DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Second + DateTime.Now.Millisecond + fa.FileName;
         //create the path to save the file to
         string fileName = Path.Combine(Server.MapPath("~/images/profiles"), file);
         //save the file to our local path
         fa.SaveAs(fileName);
         return "~/images/profiles/" + file;
     }
     else
     {
         return oldFile;
     }
 }
开发者ID:khdkhffci,项目名称:AdvancedInfo,代码行数:16,代码来源:myprofile.aspx.cs

示例15: SaveFile

 public static SaveFileResult SaveFile(string strAcct, FileUpload FileUpload, string SaveFilePath, int MaxKBSize, params string[] Extensions)
 {
     SaveFileResult result = null;
     result = new SaveFileResult();
     if ((FileUpload != null) && FileUpload.HasFile)
     {
         if (string.IsNullOrEmpty((SaveFilePath ?? "").Trim()))
         {
             result.Msg = "未設定儲存路徑";
             return result;
         }
         if ((MaxKBSize > 0) && (FileUpload.PostedFile.ContentLength > (MaxKBSize * 0x400)))
         {
             result.Msg = "超出大小限制";
             return result;
         }
         if (Extensions.Length > 0)
         {
             bool flag = false;
             foreach (string str in Extensions)
             {
                 if (Path.GetExtension(FileUpload.FileName).ToLower() == ("." + str.ToLower()))
                 {
                     flag = true;
                     break;
                 }
             }
             if (!flag)
             {
                 result.Msg = "不是允許的副檔名";
                 return result;
             }
         }
         if (Strings.Right(SaveFilePath, 1) != "/")
         {
             SaveFilePath = SaveFilePath + "/";
         }
         SetFolder(SaveFilePath);
         string str2 = strAcct + DateTime.Now.ToString("yyMMddHHmmssfff") + Path.GetExtension(FileUpload.FileName);
         string filename = HttpContext.Current.Server.MapPath(SaveFilePath + str2);
         FileUpload.SaveAs(filename);
         FileUpload.Dispose();
         result.Result = true;
         result.Msg = SaveFilePath + str2;
     }
     return result;
 }
开发者ID:patw0929,项目名称:AspNetEventSiteDemo,代码行数:47,代码来源:FileUploader.cs


注:本文中的System.Web.UI.WebControls.FileUpload.SaveAs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。