• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# WebControls.FileUpload类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



FileUpload类属于System.Web.UI.WebControls命名空间,在下文中一共展示了FileUpload类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: fileUploadName

        protected String fileUploadName(FileUpload fileupload)
        {
            try
            {
                string fileUploadDir = Server.MapPath(General.EMP_ARTICLE_LOGO + txt_Title.Text.Trim() + "/");
                if (!System.IO.Directory.Exists(fileUploadDir))
                {
                    System.IO.Directory.CreateDirectory(fileUploadDir);
                }

                System.Drawing.Image imageToBeResized = System.Drawing.Image.FromStream(fileupload.PostedFile.InputStream);
                int imageHeight = imageToBeResized.Height;
                int imageWidth = imageToBeResized.Width;
                int maxHeight = 196;
                int maxWidth = 300;
                imageHeight = (imageHeight * maxWidth) / imageWidth;
                imageWidth = maxWidth;
                if (imageHeight > maxHeight)
                {
                    imageWidth = (imageWidth * maxHeight) / imageHeight;
                    imageHeight = maxHeight;
                }
                Bitmap bitmap = new Bitmap(imageToBeResized, imageWidth, imageHeight);
                bitmap.Save(fileUploadDir + fileupload.FileName);

                return fileupload.PostedFile.FileName.ToString();
            }
            catch (Exception)
            {
                return "";
            }
        }
开发者ID:chutinhha,项目名称:teachinvietnam,代码行数:32,代码来源:RecruitmentCenter.aspx.cs


示例2: 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


示例3: GetSavedFile

        public static string GetSavedFile(FileUpload fUploader, bool autoGenerateName)
        {
            string guid = string.Empty;

            if (fUploader.PostedFile != null)
            {
                try
                {
                    if (!fUploader.PostedFile.FileName.Contains('.'))
                        return guid;
                    string[] fileext = fUploader.PostedFile.FileName.Split('.');
                    if (autoGenerateName)
                    {
                        guid = Guid.NewGuid().ToString();
                        guid += "." + fileext[fileext.Length - 1].ToString();
                    }
                    else
                        guid = fUploader.PostedFile.FileName;

                    SaveJPGWithCompressionSetting(fUploader.FileContent, ExpressoConfig.GeneralConfigElement.GetPhysicalUploadPath + guid);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
            return guid;
        }
开发者ID:yalhami,项目名称:eXpresso,代码行数:29,代码来源:Utilities.cs


示例4: CheckContainImage

 public static bool CheckContainImage(FileUpload ful)
 {
     //TODO: Kiem tra anh xem ng dùng có chọn ko?
     if (ful.HasFile)
         return true;
     else return false;
 }
开发者ID:kieungocdung,项目名称:idgwebdn,代码行数:7,代码来源:Common.cs


示例5: 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


示例6: UploadBinary

        public UploadBinary()
        {
            InnerControlID = "FileUploader";
            _fileUploadControl = new FileUpload { ID = InnerControlID };
            _info = new Label { ID = "FileUploaderInfo" };

        }
开发者ID:maxpavlov,项目名称:FlexNet,代码行数:7,代码来源:UploadBinary.cs


示例7: btnpdfUpload_Click

        protected void btnpdfUpload_Click(object sender, EventArgs e)
        {
            try
            {
                FileUpload FilePP = new FileUpload();
                FilePP = pdfFileUpload;
                if (FilePP.HasFile)
                {

                    string getExtention = Path.GetExtension(FilePP.FileName);

                    //path = path + @"\" + PPImg;

                    //FilePP.PostedFile.SaveAs(path);

                    if (getExtention == ".pdf" || getExtention == ".PDF")
                    {

                        // hidFileName.Value = filename;
                        // string path = HttpContext.Current.Server.MapPath(WebConfigurationManager.AppSettings["AttachmentPath"] + "/ModuleContents/");
                        string loc = "/download/";
                        string path = HttpContext.Current.Server.MapPath(loc);
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }

                        path = path + "fxpresent" + getExtention;

                        FilePP.PostedFile.SaveAs(path);
                        string message = "Message is <span class='actionTopic'>Your File Uploaded successfully.</span> Successfully.";
                        MyAlertBox("var callbackOk = function () { window.location = \"\"; }; SuccessAlert(\"" +
                                   "Process Succeed" + "\", \"" + message + "\", \"\");");

                    }
                    else
                    {
                        string message = "Message is <span class='actionTopic'>Your File extension does not match.</span> Successfully.";
                        MyAlertBox("var callbackOk = function () { window.location = \"\"; }; WarningAlert(\"" +
                                   "Process Succeed" + "\", \"" + message + "\", \"\");");

                    }

                }
                else
                {
                    string message = " <span class='actionTopic'>" + "Sorry Please Select Your File." + "</span>.";
                    MyAlertBox("var callbackOk = function () { window.location = \"\"; }; WarningAlert(\"" + "Warning!!" + "\", \"" + message + "\",\"\");");

                }

            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; }
                MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");

            }
        }
开发者ID:atiburrahman09,项目名称:globalfxusa,代码行数:60,代码来源:upload.aspx.cs


示例8: AddControl

        private static HtmlTableCell AddControl(JobControl_Get_Result control)
        {
            HtmlTableCell cell = new HtmlTableCell();
            Control c = new Control();

            switch (control.ControlTypeName)
            {
                case "TextBox":
                    c = new TextBox();
                    c.ID = control.JobControlID + control.ControlTypeName + control.ControlName;
                    break;

                case "CheckBox":
                    c = new CheckBox();
                    c.ID = control.JobControlID + control.ControlTypeName + control.ControlName;
                    break;

                case "ImageUpload":
                    c = new FileUpload();
                    c.ID = control.JobControlID + control.ControlTypeName + control.ControlName;
                    break;
            }

            cell.Controls.Add(c);
            return cell;
        }
开发者ID:TCarmack,项目名称:Brentwood,代码行数:26,代码来源:FormBuilder.cs


示例9: 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


示例10: Create

        public ActionResult Create(HttpPostedFileBase file)
        {
            //foreach (string file in Request.Files)
            //{
            //	HttpPostedFile hpf = Request.Files[file] as HttpPostedFile;
            //	if (hpf.ContentLength == 0)
            //		continue;
            //	string savedFileName = Path.Combine(
            //	   AppDomain.CurrentDomain.BaseDirectory,
            //	   Path.GetFileName(hpf.FileName));
            //	hpf.SaveAs(savedFileName);
            //}

            Flyer flyer = new Flyer();
            if (TryUpdateModel(flyer))
            {
                //UPLOAD THE FLYER
                FileUpload uploader = new FileUpload();
                var fileName = Path.GetFileName(file.FileName);
                var path = Path.Combine(Server.MapPath("~/resources/flyers"), fileName);
                file.SaveAs(path);
                flyer.Location = path;
                _flyerRepository.Create(flyer);
                //TODO create flyer
                //flyers.CreateFlyer(flyer);
                return RedirectToAction("Index");
            }

            return View();
        }
开发者ID:MarneeDear,项目名称:Terminal-Management-Applications,代码行数:30,代码来源:FlyersController.cs


示例11: UploadBrandLogo

        private string UploadBrandLogo(int BrandID,FileUpload fu)
        {
            string ImageUrl, ImageShortUrl, Message;
            CommonImageUpload.Upload(fu, out ImageUrl, out ImageShortUrl, out Message);

            return ImageShortUrl;
        }
开发者ID:ViniciusConsultor,项目名称:noname-netshop,代码行数:7,代码来源:Add.aspx.cs


示例12: GetFileUpload

        private static FileUpload GetFileUpload(string id)
        {
            FileUpload fileUpload = new FileUpload();
            fileUpload.ID = id;

            return fileUpload;
        }
开发者ID:ravikumr070,项目名称:mixerp,代码行数:7,代码来源:ImageUpload.cs


示例13: FileSc

 /// <summary>
 /// 上传文件
 /// </summary>
 /// <param name="PosPhotoUpload">控件</param>
 /// <param name="saveFileName">保存的文件名</param>
 /// <param name="imagePath">保存的文件路径</param>
 public string FileSc(FileUpload PosPhotoUpload, string saveFileName, string imagePath)
 {
     string state = "";
     if (PosPhotoUpload.HasFile)
     {
         if (PosPhotoUpload.PostedFile.ContentLength / 1024 < 10240)
         {
             string MimeType = PosPhotoUpload.PostedFile.ContentType;
             if (String.Equals(MimeType, "image/gif") || String.Equals(MimeType, "image/pjpeg"))
             {
                 string extFileString = System.IO.Path.GetExtension(PosPhotoUpload.PostedFile.FileName);
                 PosPhotoUpload.PostedFile.SaveAs(HttpContext.Current.Server.MapPath(imagePath));
             }
             else
             {
                 state = "上传文件类型不正确";
             }
         }
         else
         {
             state = "上传文件不能大于10M";
         }
     }
     else
     {
         state = "没有上传文件";
     }
     return state;
 }
开发者ID:dayuhan,项目名称:NETWORK,代码行数:35,代码来源:FileUp.cs


示例14: AlbumImageUpLoad

 public  enum enumState{ noFile,fileEx,fileSuccess,fileFailed};//0没选中文件;1扩展名出错;2成功;3失败;
 //图片上传
 public enumState AlbumImageUpLoad(FileUpload fileUpload, string urlPath, string filename)
 {
     if (fileUpload.PostedFile.FileName == "")
     { 
         return enumState.noFile;
     }
     else
     {
         string filepath = fileUpload.PostedFile.FileName; 
         string fileEx = filepath.Substring(filepath.LastIndexOf(".") + 1);//string filename = lbRandomCode.Text + "."; 
         string serverpath = urlPath + filename + "." + fileEx;                //string serverpath = Server.MapPath("~/Images/Album/") + filename + fileEx;
         if (fileEx == "jpg" || fileEx == "bmp" || fileEx == "gif" || fileEx == "JPG" || fileEx == "BMP" || fileEx == "GIF")
         {
             fileUpload.PostedFile.SaveAs(serverpath);
             //imgAlbumCover.ImageUrl = "~/Images/Album/" + filename + fileEx;
             //lbImageUrl.Text = "~/Images/Album/" + filename + fileEx; 
             //imgAlbumCover.ImageUrl = lbImageUrl.Text;
             return enumState.fileSuccess;
         }
         else
         {
             return enumState.fileEx;
         }
     } 
 }
开发者ID:xueshijun,项目名称:0.Undergraduation-Design,代码行数:27,代码来源:PicturesItem.cs


示例15: Upload

 public string Upload(FileUpload fileUpload, string ftpServerIP, string ftpUserID, string ftpPassword)
 {
     string filename = fileUpload.FileName;
     string sRet = "上传成功!";
     FileInfo fileInf = new FileInfo(fileUpload.PostedFile.FileName);
     string uri = "ftp://" + ftpServerIP + "/" + filename;
     FtpWebRequest reqFTP = (FtpWebRequest)WebRequest.Create(new Uri(uri));
     reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
     reqFTP.KeepAlive = false;
     reqFTP.Method = "STOR";
     reqFTP.UseBinary = true;
     reqFTP.UsePassive = false;
     reqFTP.ContentLength = fileInf.Length;
     int buffLength = 2048;
     byte[] buff = new byte[buffLength];
     FileStream fs = fileInf.OpenRead();
     try
     {
         Stream strm = reqFTP.GetRequestStream();
         for (int contentLen = fs.Read(buff, 0, buffLength); contentLen != 0; contentLen = fs.Read(buff, 0, buffLength))
         {
             strm.Write(buff, 0, contentLen);
         }
         strm.Close();
         fs.Close();
     }
     catch (Exception ex)
     {
         sRet = ex.Message;
     }
     return sRet;
 }
开发者ID:uwitec,项目名称:web-mvc-logistics,代码行数:32,代码来源:FTPHelper.cs


示例16: Imagem

 public Imagem(FileUpload FileUpload, HiddenField Hidden, string Path, string Arquivo)
 {
     this.FileUpload = FileUpload;
     this.Hidden = Hidden;
     this.Path = Path;
     this.Arquivo = Arquivo;
 }
开发者ID:Janailson,项目名称:loja,代码行数:7,代码来源:Imagem.cs


示例17: FileSc

 public string FileSc(FileUpload PosPhotoUpload, string saveFileName, string imagePath)
 {
     string state = "";
     if (PosPhotoUpload.HasFile)
     {
         if (PosPhotoUpload.PostedFile.ContentLength / 1024 < 10240)
         {
             string MimeType = PosPhotoUpload.PostedFile.ContentType;
             if (String.Equals(MimeType, "image/gif") || String.Equals(MimeType, "image/pjpeg"))
             {
                 PosPhotoUpload.PostedFile.SaveAs(HttpContext.Current.Server.MapPath(imagePath));
             }
             else
             {
                 state = "";
             }
         }
         else
         {
             state = "";
         }
     }
     else
     {
         state = "";
     }
     return state;
 }
开发者ID:devworker55,项目名称:Mammatus,代码行数:28,代码来源:FileUp.cs


示例18: FileUpload

 /// <summary>
 /// 文件上传
 /// </summary>
 /// <param name="path">保存路径</param>
 /// <param name="filleupload">上传文件控件</param>
 /// <param name="filename">文件名</param>
 /// <param name="fileExtension">后缀名</param>
 /// <param name="filesize">文件大小</param>
 /// <returns></returns>
 public static string FileUpload(FileUpload filleupload, string path, out string filename, out string fileExtension, out string filesize)
 {
     string FileName = CommonHelper.GetGuid;
     if (Directory.Exists(path) == false)//如果不存在就创建file文件夹
     {
         Directory.CreateDirectory(path);
     }
     //取得文件的扩展名,并转换成小写
     string Extension = System.IO.Path.GetExtension(filleupload.FileName).ToLower();
     fileExtension = Extension;
     filename = FileName + Extension;
     //取得文件大小
     filesize = FileHelper.CountSize(filleupload.PostedFile.ContentLength);
     try
     {
         int Size = filleupload.PostedFile.ContentLength / 1024 / 1024;
         if (Size > 10)
         {
             return "上传失败,文件过大";
         }
         else
         {
             filleupload.PostedFile.SaveAs(path + filename);
             return "上传成功";
         }
     }
     catch (Exception)
     {
         return "上传失败";
     }
 }
开发者ID:xiaolin8,项目名称:AMS,代码行数:40,代码来源:UploadHelper.cs


示例19: 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


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# WebControls.FormView类代码示例发布时间:2022-05-26
下一篇:
C# WebControls.DropDownList类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap