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


C# FileUpload类代码示例

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


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

示例1: 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:RushHang,项目名称:H_DataAssembly,代码行数:35,代码来源:FileUp.cs

示例2: VerificarEnLoad

 public Boolean VerificarEnLoad(FileUpload fup, Label lbl)
 {
     if (VerificarFileUpload(fup))
     {
         //Esto es para la vista previa...
         //try
         //{
         //    fup.PostedFile.SaveAs(Server.MapPath("~/Temp/") + fup.FileName);
         //    lbl.Text = "¡Archivo subido con exito!";
         //    return true;
         //}
         //catch (Exception ex)
         //{
         //    lbl.Text = "¡El archivo no se pudo subir." + ex.Message;
         //    return false;
         //}
         lbl.Text = "¡Archivo subido con exito!";
         return true;
     }
     else
     {
         if (fup.FileName != null)
         {
             lbl.Text = "";
         }
         else
         {
             lbl.Text = "¡TIPO de archivo incorrecto";
         }
         return false;
     }
 }
开发者ID:kaiss78,项目名称:ecbues,代码行数:32,代码来源:ManipularPregunta.ascx.cs

示例3: FileUpload

    public string FileUpload(FileUpload fu)
    {
        string backupFile = "";
        if (fu.PostedFile.FileName != "")
        {
            backupFile = fu.PostedFile.FileName.Substring(fu.PostedFile.FileName.LastIndexOf(@"\") + 1);//RT_EDITS_DOC_SET_CONTENTS_20080319.csv

            if (backupFile != "")
            {
                if (backupFile.Substring(0, 2) == "CT")
                {
                    fu.PostedFile.SaveAs(ConfigurationManager.AppSettings["FilePath"] + @"\CT\" + backupFile);//
                }
                else if (backupFile.Substring(0,2)=="RT")
                {
                    fu.PostedFile.SaveAs(ConfigurationManager.AppSettings["FilePath"] + @"\RT\" + backupFile);//
                }
                else// new second RT
                {
                    fu.PostedFile.SaveAs(ConfigurationManager.AppSettings["FilePath"] + @"\NSRT\" + backupFile);//
                }
            }
        }
        else
        {
            backupFile = "";
        }

        return backupFile;
    }
开发者ID:wra222,项目名称:testgit,代码行数:30,代码来源:HP_UpLoadFile.aspx.cs

示例4: ImageWidth

    public int ImageWidth(FileUpload fuName)
    {
        #region Remark
        /*############################ Example ############################
        ใช้หาขนาดความกว้างของรูป จาก FileUpload Control
        clsIO.ImageWidth(FileUploadControl).ToString()
        
        TIP : สามารถเรียกใช้ได้ครั้งละ 1 Function คือ ImageWidth หรือ ImageHeight เท่านั้น เพราะค่าใน FileUpload จะหายไป
        #################################################################*/
        #endregion

        int imgWidth = 0;

        if (fuName.HasFile)
        {
            if (FileTypeChecker(fuName.FileName) == "IMG")
            {
                Stream myStream = fuName.PostedFile.InputStream;
                System.Drawing.Image myImage = System.Drawing.Image.FromStream(myStream);

                if (myImage != null)
                {
                    imgWidth = myImage.Width;
                    myImage.Dispose();
                    myStream.Dispose();
                }
            }
        }

        return imgWidth;
    }
开发者ID:oofdui,项目名称:ChanthaburiHospital.com,代码行数:31,代码来源:clsIO.cs

示例5: CheckDocRequired

 private bool CheckDocRequired(FileUpload fuDocrequired, string[] validFileTypes)
 {
     int valid_up = 0;
     if (1 == 1)
     {
         int has_file = 0;
         if (fuDocrequired.HasFile)
         {
             ++has_file;
             string ext = System.IO.Path.GetExtension(fuDocrequired.PostedFile.FileName);
             bool isValidFile = false;
             for (int j = 0; j < validFileTypes.Length; j++)
             {
                 if (ext.ToLower() == "." + validFileTypes[j].ToLower())
                 {
                     isValidFile = true;
                     //lblStatus.Text = "Valid";
                     ++valid_up;
                     break;
                 }
             }
             if (!isValidFile)
             {
                 //lblStatus.Text = "Not Valid";
                 //lblUP_Error.Text = "Invalid File. Please upload a File with extension " + string.Join(",", validFileTypes);
             }
         }
         else { }
     }
     return (valid_up > 0) ? true : false;
 }
开发者ID:haslam,项目名称:ELIZADE,代码行数:31,代码来源:AddGalleryControl.ascx.cs

示例6: uploadProof

    private string uploadProof(FileUpload upload)
    {
        string result = "";
        if ((upload.PostedFile != null) && (upload.PostedFile.ContentLength > 0))
        {
            string fn = "GamesResult";
            string ext = System.IO.Path.GetExtension(upload.PostedFile.FileName);
            string fileName = "Games" + "\\" + fn + "_" + DateTime.Now.Day + "_" + DateTime.Now.Month + "_" +
                              DateTime.Now.Year + ext;
            string SaveLocation = Server.MapPath("Attachments") + "\\" + fileName;
            try
            {
                double size = ((double)FileUpload1.PostedFile.ContentLength) / (1024 * 1024);

                if (!Directory.Exists(Server.MapPath("Attachments") + "\\Games"))
                    Directory.CreateDirectory(Server.MapPath("Attachments") + "\\Games");
                FileUpload1.PostedFile.SaveAs(SaveLocation);

                result = SaveLocation;

            }
            catch (Exception)
            {
                //message
            }
        }
        else result = "Empty";

        return result;
    }
开发者ID:Thulasizwe,项目名称:Dynamic-Trio,代码行数:30,代码来源:SubmitResult.aspx.cs

示例7: Upload

 protected void Upload(FileUpload uploader, Label lblStatus)
 {
     if (uploader.PostedFile.ContentLength != 0) {
         try {
             if (uploader.PostedFile.ContentLength > 100000) {
                 lblStatus.Text = "File is too large for upload";
             } else {
                 using (StreamReader sr = new StreamReader(uploader.PostedFile.InputStream)) {
                     string line = null;
                     string[] split = null;
                     char[] sep = { ',' };
                     var headers = sr.ReadLine().Split(sep).Skip(1);
                     while ((line = sr.ReadLine()) != null) {
                         split = line.Split(sep);
                         AddToTypedTable(split, headers);
                     }
                 }
                 RSMTenon.Data.DataUtilities.UploadToDatabase(Table, TableName, null);
                 lblStatus.Text = String.Format("{0:#,##0} row(s) added to database", Table.Rows.Count);
             }
         } catch (Exception err) {
             lblStatus.Text = err.Message;
         }
     }
 }
开发者ID:garsiden,项目名称:Report-Generator,代码行数:25,代码来源:UploadPage.cs

示例8: btnSubmit_Click

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        pnlInput.Style.Add(HtmlTextWriterStyle.Display, "none");
        user u = Users.Get(db, userName);
        try
        {
            ticket newTicket = Tickets.Add(db, Server.HtmlEncode(txtTopic.Text), txtDetails.Text, Int32.Parse(ddlSubUnit.SelectedValue), Int32.Parse(ddlPriority.SelectedValue), u.id, u.sub_unit);

            FileUpload[] fuControls = new FileUpload[] { FileUpload1, FileUpload2, FileUpload3, FileUpload4, FileUpload5 };
            Tickets.Attachments.SaveMultiple(db, fuControls, newTicket.id, 0);
            string body = GetLocalResourceObject("ANew").ToString() +ddlPriority.SelectedItem.Text+" "+ GetLocalResourceObject("TicketWasSubmittedBy").ToString()+" " + u.userName + " (" + u.sub_unit1.unit.unit_name + " - " + u.sub_unit1.sub_unit_name + ") \n\n";
            body += newTicket.title + " [" + Resources.Common.TicketNumber + " #" + newTicket.id + "]\n\n" + Request.Url.OriginalString.Replace("new_ticket.aspx", string.Empty) + "ticket.aspx?ticketid=" + newTicket.id;
           
            pnlOutput.Visible = true;
            if ((bool.Parse(Utils.Settings.Get("email_notification"))))
            {
                try
                {
                    Utils.SendEmail(newTicket.sub_unit.mailto, "New " + ddlPriority.SelectedItem.Text.ToLower() + " " + Resources.Common.Priority.ToLower() + " " + Resources.Common.Ticket.ToLower() + " " + Resources.Common.AssignedTo.ToLower() + " " + newTicket.sub_unit.unit.unit_name + " - " + newTicket.sub_unit.sub_unit_name, body);
                    lblSentTo.Text = "<span class='bold'>" + newTicket.sub_unit.unit.unit_name + " - " + newTicket.sub_unit.sub_unit_name + "</span> " + GetLocalResourceObject("HasBeenNotified").ToString();
                }
                catch (Exception ex)
                {
                    lblSentTo.report(false, "<br />" + Resources.Common.EmailError, ex);
                }
            }
            lblTicketNumber.Text = "<a href='ticket.aspx?ticketID=" + newTicket.id.ToString() + "'>" + newTicket.id.ToString() + "</a>";
        }
        catch (Exception ex)
        {
            lblReport.report(false, Resources.Common.Error, ex);
            pnlError.Visible = true;
        }
    }
开发者ID:EdiCarlos,项目名称:MyPractices,代码行数:34,代码来源:new_ticket.aspx.cs

示例9: Upload

    private void Upload(FileUpload fu, string name)
    {
        if (fu.HasFile)
        {
            try
            {
                string filename = System.IO.Path.GetFileName(fu.FileName);
                string fileUpload = Server.MapPath(@"~/Data/Images/") + filename;
                if (System.IO.File.Exists(fileUpload))
                    System.IO.File.Delete(fileUpload);
                fu.SaveAs(fileUpload);
                System.Drawing.Image image1 = System.Drawing.Image.FromFile(fileUpload);
                string fileAceess = Server.MapPath(@"~/Data/Images/" + name + ".jpg");
                if (System.IO.File.Exists(fileAceess))
                    System.IO.File.Delete(fileAceess);
                image1.Save(fileAceess, System.Drawing.Imaging.ImageFormat.Jpeg);
                if (System.IO.File.Exists(fileUpload))
                    System.IO.File.Delete(fileUpload);
            }
            catch (Exception ex)
            {

            }
        }
    }
开发者ID:tmtien05,项目名称:WebVanTai,代码行数:25,代码来源:SYS_Setup.aspx.cs

示例10: UploadTestFileAsync

 public static async Task<string> UploadTestFileAsync()
 {
     // Upload file
     var filePath = TestFilePath;
     var upload = new FileUpload("image/png", Unique.String + ".png");
     return await upload.UploadFileAsync(filePath);
 }
开发者ID:ytokas,项目名称:appacitive-dotnet-sdk,代码行数:7,代码来源:FileHelper.cs

示例11: 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,代码来源:WebUtils.cs

示例12: OperatePhoto

 /// <summary>
 /// 图片上传函数
 /// </summary>
 /// <param name="employeeId">员工编号</param>
 /// <param name="photoFile">文件上传控件</param>
 public void OperatePhoto(int employeeId, FileUpload photoFile)
 {
     //如果上传文件为空则不执行此代码。
     if (photoFile == null || photoFile.HasFile == false) return;
      //获取文件的输入流
     Stream imageStream = photoFile.PostedFile.InputStream;
     int imageLength = photoFile.PostedFile.ContentLength;
     string imageType = photoFile.PostedFile.ContentType;
     MemoryStream mStream = new MemoryStream();
     byte[] imageData = new byte[1024];
     int count = 0;
     while (0 < (count = imageStream.Read(imageData, 0, imageData.Length)))
     {
         //将文件流转换为字节,然后写入到数据库中
         mStream.Write(imageData, 0, count);
     }
     string connstr = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
     using (SqlConnection conn = new SqlConnection(connstr))
     {
         conn.Open();
         using (SqlCommand cmd =new SqlCommand("Update Employees Set Photo = @Photo WHERE EmployeeID = @EmployeeID",conn))
         {
             //更新员工照片信息
             cmd.Parameters.AddWithValue("@EmployeeID", employeeId);
             cmd.Parameters.AddWithValue("@photo", photoFile);
             cmd.ExecuteNonQuery();
         }
     }
 }
开发者ID:AJLoveChina,项目名称:workAtQmm,代码行数:34,代码来源:Default.aspx.cs

示例13: UpdateDocumentDetails

    public void UpdateDocumentDetails()
    {
        string DocName = default(System.String);
        int DocStatus = default(System.Int32);
        int OppsID = default(System.Int32);
        System.DateTime LastModifyDate = default(System.DateTime);

        //For LastModifyDate
        {
            TextBox LastModifyDateCal = new TextBox();
            LastModifyDateCal = (TextBox)DocumentDW.FindControl("LastModifyDate");
            if ((LastModifyDateCal != null))
            {
                if (!string.IsNullOrEmpty(LastModifyDateCal.Text))
                {
                    LastModifyDate = Convert.ToDateTime(LastModifyDateCal.Text.Trim());
                }
            }

        }
        //For Document Status
        DropDownList DocStatusDDList = new DropDownList();
        DocStatusDDList = (DropDownList)DocumentDW.FindControl("ddlDocStatus");
        if ((DocStatusDDList != null))
        {
            DocStatus = Convert.ToInt32(DocStatusDDList.SelectedValue);

        }
        //For Opportunity
        DropDownList OpportunityDDList = new DropDownList();
        OpportunityDDList = (DropDownList)DocumentDW.FindControl("ddlOpportunity");
        if ((OpportunityDDList != null))
        {
            OppsID = Convert.ToInt32(OpportunityDDList.SelectedValue);

        }
        FileUpload FileUploadControl = new FileUpload();
        FileUploadControl = (FileUpload)DocumentDW.FindControl("Upload");
        if ((FileUploadControl != null))
        {
            //Add GUID
            DocName = System.Guid.NewGuid() + "_" + FileUploadControl.FileName.ToString();
            if (string.IsNullOrEmpty(DocName))
            {
                //User has not uploaded new file so keep the same filename
                DocName = hidDocumentName.Value;
            }
            else
            {
                //Save the actual file in the documents folder
                //FileUploadControl.SaveAs(Server.MapPath(DocName));
                //FileUploadControl.SaveAs(ConfigurationManager.AppSettings["DocumentsUploadLocation"] + DocName);
                FileUploadControl.SaveAs(Server.MapPath(ConfigurationManager.AppSettings["DocumentsUploadLocation"] + DocName));
            }

        }
        //Now Update
        new SandlerRepositories.DocumentsRepository().Update(Convert.ToInt32(hidDocumentID.Value), OppsID, DocName, DocStatus, LastModifyDate,CurrentUser);
    }
开发者ID:jigshGitHub,项目名称:SandlerTrainingDevelopment,代码行数:59,代码来源:Detail.aspx.cs

示例14: FileUploadAsyncTest

 public async Task FileUploadAsyncTest()
 {
     var file = FileHelper.TestFilePath;
     var filename = Unique.String + ".png";
     Console.WriteLine("Generated file name: {0}", filename);
     var handler = new FileUpload("image/png", filename);
     var uploadedFilename = await handler.UploadFileAsync(file);
     Console.WriteLine("Uploaded to file {0}", uploadedFilename);
 }
开发者ID:beer-bahadur,项目名称:appacitive-dotnet-sdk,代码行数:9,代码来源:FileFixture.cs

示例15: GetImage

 private void GetImage(ref List<byte[]> photolist, FileUpload con)
 {
     HttpPostedFile photo = con.PostedFile;
     int upPhotoLength = photo.ContentLength;
     byte[] PhotoArray = new Byte[upPhotoLength];
     Stream PhotoStream = photo.InputStream;
     PhotoStream.Read(PhotoArray, 0, upPhotoLength);
     photolist.Add(PhotoArray);
 }
开发者ID:hhxyzsm,项目名称:Ordering,代码行数:9,代码来源:Default.aspx.cs


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