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


C# UploadedFile.SaveAs方法代码示例

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


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

示例1: SavePostedFile

 public static string SavePostedFile(UploadedFile uploadedFile)
 {
     string ret = "";
     if (uploadedFile.IsValid)
     {
         string fileToSave = FileUtils.GetUploadedFileLocalName(uploadedFile.FileName);
         uploadedFile.SaveAs(fileToSave);
         ret = fileToSave;
     }
     return ret;
 }
开发者ID:ddksaku,项目名称:canon,代码行数:11,代码来源:FileUtils.cs

示例2: SavePostedFile

        private void SavePostedFile(UploadedFile uploadedFile, string titulo, string descricao)
        {
            string thumbName = uploadedFile.FileName.Substring(0, uploadedFile.FileName.IndexOf('.')) + "_thumb" + uploadedFile.FileName.Substring(uploadedFile.FileName.IndexOf('.'));

            //Monta o nome do arquivo.
            string fileName = System.IO.Path.Combine(MapPath(UploadDirectory), thumbName);

            //Recupera a imagem
            using (System.Drawing.Image original = System.Drawing.Image.FromStream(uploadedFile.FileContent))

            //Recupera a imagem no formato menor (thumb)
            using (System.Drawing.Bitmap thumbnail = PhotoUtils.CreateThumbnail(original, 150))
            {
                //Salva o thumb da foto
                PhotoUtils.SaveToJpeg(thumbnail, fileName, 100);
            }

            //Salva o arquivo enviado (foto em tamanho padrao)
            uploadedFile.SaveAs(System.IO.Path.Combine(MapPath(UploadDirectory), uploadedFile.FileName));

            try
            {
                //Inserindo o album
                if (!string.IsNullOrEmpty(titulo) && !string.IsNullOrEmpty(descricao))
                    new BannerSiteBU().InserirBanner(titulo, UploadDirectory, uploadedFile.FileName, DateTime.Now, UploadDirectory, thumbName, descricao);
                    //new AlbumFotosBU().InserirAbum(titulo, descricao, "pag_empresa", UploadDirectory, thumbName);
                else
                    throw new Exception("Parâmetros nulos ou inválidos. Favor verifique o conteúdo inserido nos campos Título e Descrição do Banner!");
            }
            catch (Exception eX)
            {
                throw eX;
            }
        }
开发者ID:hugohcn,项目名称:sme_website,代码行数:34,代码来源:ManterBannerSiteForm.aspx.cs

示例3: SavePostedFile

        private void SavePostedFile(UploadedFile uploadedFile, string titulo, string descricao)
        {
            string thumbName = uploadedFile.FileName.Substring(0,uploadedFile.FileName.IndexOf('.')) + "_thumb" + uploadedFile.FileName.Substring(uploadedFile.FileName.IndexOf('.'));

            //Monta o nome do arquivo.
            string fileName = System.IO.Path.Combine(MapPath(UploadDirectory), thumbName);

            //Recupera a imagem
            using (System.Drawing.Image original = System.Drawing.Image.FromStream(uploadedFile.FileContent))

            //Recupera a imagem no formato menor (thumb)
            using (System.Drawing.Bitmap thumbnail = PhotoUtils.CreateThumbnail(original, 150))
            {
                //Salva o thumb da foto
                PhotoUtils.SaveToJpeg(thumbnail, fileName, 100);
            }

            //Salva o arquivo enviado (foto em tamanho padrao)
            uploadedFile.SaveAs(System.IO.Path.Combine(MapPath(UploadDirectory), uploadedFile.FileName));

            //Salva os dados no banco
            new AlbumFotosBU().SalvarFoto(Convert.ToInt32(Request.QueryString["idAlbum"].ToString()), titulo, descricao, UploadDirectory, uploadedFile.FileName, UploadDirectory, thumbName);
        }
开发者ID:hugohcn,项目名称:sme_website,代码行数:23,代码来源:ManterAlbumFotografiaForm.aspx.cs

示例4: SavePostedFiles

    string SavePostedFiles(UploadedFile uploadedFile)
    {
        if (!uploadedFile.IsValid)
            return string.Empty;
        DataSourceSelectArguments dsSA = new DataSourceSelectArguments();
        DataView returnedDataView = (DataView)dsInfo.Select(dsSA);
        string strMaSo = "";
        if (Session["UserID"].ToString() != null)
            strMaSo = Session["UserID"].ToString() + "_" + DateTime.Now.ToString("ddMMyyyyhhmmss");
        else
            strMaSo = DateTime.Now.ToString("ddMMyyyyhhmmss");
        FileInfo fileInfo = new FileInfo(uploadedFile.FileName);
        string strExp = fileInfo.Name;
        int Index = strExp.LastIndexOf('.');
        strExp = strExp.Substring(Index, strExp.Length - Index);
        if (strExp.Length <= 0)
            strExp = "";
        string uploadFolder = Server.MapPath("~/img/UserAvata");

        uploadedFile.SaveAs(uploadFolder + "/" + strMaSo + strExp);

        //CutImage150("~/img/UserAvata", 150, fileInfo.Name);
        return strMaSo + strExp;
    }
开发者ID:trantrung2608,项目名称:ilinkbay,代码行数:24,代码来源:UserInfo.aspx.cs

示例5: SavePostedFile

        private string SavePostedFile(UploadedFile uploadedFile)
        {
            if (!uploadedFile.IsValid)
                return "File is not valid";

            var usersDal = new UsersDal();

            var fileExtension = GetExtension(uploadedFile.FileName);

            var guid = Guid.NewGuid();

            var dirPath = MapPath(UploadDirectory + AuthProvider.GetNameWithoutDomain(Page.User.Identity.Name));
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);

            }

            string fileName = Path.Combine(dirPath, guid.ToString() + fileExtension);
            uploadedFile.SaveAs(fileName, true);

            //create a Bitmap from the file and add it to the list
            var bitmap = new Bitmap(fileName);
            if (bitmap.Height > 128 || bitmap.Width > 128)
            {

                return "File size is invalid. Image can not be bigger than 128x128 pixels.";
            }

            usersDal.RegisterNewUserAvatar(guid.ToString() + fileExtension, AuthProvider.UserKey(Session));

            //clear old Data

            var emblemKey = usersDal.GetUserEmblem(AuthProvider.UserKey(Session));
            var avatarKey = usersDal.GetUserAvatar(AuthProvider.UserKey(Session));

            var filePath1 = dirPath + "\\" + (avatarKey ?? string.Empty);
            var filePath2 = dirPath + "\\" + (emblemKey ?? string.Empty);

            foreach (var f in Directory.GetFiles(dirPath))
            {
                try
                {
                    if ((f != filePath1) && (f != filePath2))
                        File.Delete(f);
                }
                catch (Exception)
                {
                }
            }
            return string.Empty;
        }
开发者ID:Letractively,项目名称:dc-gamification,代码行数:52,代码来源:UserProfile.ascx.cs

示例6: UploadFile

 public static void UploadFile(int ID, UploadedFile file, bool isRevision)
 {
     var destination = HttpContext.Current.Server.MapPath("~/uploads/" + ID + "/");
     if (!System.IO.Directory.Exists(destination))
         System.IO.Directory.CreateDirectory(destination);
     // let's file the files accordingly, then add an entry to the files table in the db
     file.SaveAs(destination + file.FileName, true);
     WO.AddFile(ID, file.FileName, isRevision);
 }
开发者ID:AdamWebDev,项目名称:HUWO2,代码行数:9,代码来源:WO.cs

示例7: ExtrairArquivoZip

        private void ExtrairArquivoZip(UploadedFile arquivo, string pastaDeDestino)
        {
            IList<IRevistaDePatente> listaRevistasAProcessar = new List<IRevistaDePatente>();
            var revistaDePatente = FabricaGenerica.GetInstancia().CrieObjeto<IRevistaDePatente>();
            var numeroRevista = arquivo.GetNameWithoutExtension();

            revistaDePatente.NumeroRevistaPatente = Convert.ToInt32(numeroRevista.Substring(0, 1).ToUpper().Equals("P") ? numeroRevista.Substring(1, 4) : numeroRevista);

            var pastaDeDestinoTemp = Server.MapPath(UtilMP.URL_REVISTA_PATENTE + "/temp/");

            Directory.CreateDirectory(pastaDeDestinoTemp);

            var caminhoArquivoZip = Path.Combine(pastaDeDestinoTemp, revistaDePatente.NumeroRevistaPatente + arquivo.GetExtension());

            arquivo.SaveAs(caminhoArquivoZip, true);

            Util.DescompacteArquivoZip(caminhoArquivoZip, pastaDeDestinoTemp);

            File.Delete(caminhoArquivoZip);

            var dirInfo = new DirectoryInfo(pastaDeDestinoTemp);

            FileInfo[] arquivos = dirInfo.GetFiles();

            foreach (var arquivoDaPasta in arquivos)
            {
                var caminhoArquivoAntigo = Path.Combine(pastaDeDestinoTemp, arquivoDaPasta.Name);

                if (arquivoDaPasta.Name.Equals("P" + revistaDePatente.NumeroRevistaPatente + arquivoDaPasta.Extension))
                {
                    var arquivoNovo = arquivoDaPasta.Name.Replace("P" + revistaDePatente.NumeroRevistaPatente + arquivoDaPasta.Extension,
                                                revistaDePatente.NumeroRevistaPatente.ToString() + arquivoDaPasta.Extension);

                    var caminhoArquivoNovo = Path.Combine(pastaDeDestino, arquivoNovo);

                    File.Delete(caminhoArquivoNovo);
                    File.Move(caminhoArquivoAntigo, caminhoArquivoNovo);
                    File.Delete(caminhoArquivoAntigo);

                    revistaDePatente.ExtensaoArquivo = arquivoDaPasta.Extension;
                    listaRevistasAProcessar.Add(revistaDePatente);

                    MostraListaRevistasAProcessar(listaRevistasAProcessar);
                    return;
                }
                if (arquivoDaPasta.Name.Replace(arquivoDaPasta.Extension, "").Equals(revistaDePatente.NumeroRevistaPatente.ToString()))
                {
                    var arquivoNovo = revistaDePatente.NumeroRevistaPatente.ToString() + arquivoDaPasta.Extension;

                    var caminhoArquivoNovo = Path.Combine(pastaDeDestino, arquivoNovo);

                    File.Delete(caminhoArquivoNovo);
                    File.Move(caminhoArquivoAntigo, caminhoArquivoNovo);
                    File.Delete(caminhoArquivoAntigo);

                    revistaDePatente.ExtensaoArquivo = arquivoDaPasta.Extension;
                    listaRevistasAProcessar.Add(revistaDePatente);

                    MostraListaRevistasAProcessar(listaRevistasAProcessar);
                    return;
                }
            }

            revistaDePatente.ExtensaoArquivo = arquivo.GetExtension();
            listaRevistasAProcessar.Add(revistaDePatente);

            MostraListaRevistasAProcessar(listaRevistasAProcessar);
        }
开发者ID:ViniciusConsultor,项目名称:petsys,代码行数:68,代码来源:frmLeituraRevistaPatente.aspx.cs

示例8: UpdatePhoto

        protected void UpdatePhoto(object sender, EventArgs e)
        {
            if (ruUserImage.UploadedFiles.Count > 0)
            {
                newFile = ruUserImage.UploadedFiles[0];
                /* is the file name of the uploaded file 50 characters or less?  
                    * The database field that holds the file name is 50 chars.
                    * */
                if (newFile.ContentLength > AppSettings.ProfileImageMaxFileSize)
                {
                    lblUpdateResults.Text = "The file being imported is too big. Please select another file.";
                }
                else
                {
                    if (newFile.GetName().Length <= AppSettings.ProfileImageMaxFileNameLength)
                    {
                        var uploadFolder = Server.MapPath(AppSettings.ProfileImageUserWebPath);

                        string newFileName;

                        do
                        {
                            newFileName = (Path.GetRandomFileName()).Replace(".", "") +
                                          newFile.GetExtension();
                        } while (System.IO.File.Exists(Path.Combine(uploadFolder, newFileName)));

                        try
                        {
                            newFile.SaveAs(Path.Combine(uploadFolder, newFileName));

                            var oUser = SessionObject.LoggedInUser;
                            var successful = oUser.UpdateUserImageFilename(newFileName);
                            if (successful)
                            {
                                //attempt to delete the old file
                                if (imgPhoto.Src != "/Images/person.png")
                                {
                                    var oldFilePath = Server.MapPath(imgPhoto.Src);
                                    File.Delete(oldFilePath);
                                }
                                oUser.ImageFilename = newFileName;
                                SessionObject.LoggedInUser = oUser;

                                imgPhoto.Src = AppSettings.ProfileImageUserWebPath + "/" + newFileName;
                            }
                            else
                            {
                                lblUpdateResults.Text = "Database error. Please contact system administrator.";
                            }
                        }
                        catch (Exception ex)
                        {
                            lblUpdateResults.Text = "Image Import unsuccessful. Please contact system adminstrator.";
                        }
                    }
                    else
                    {
                        lblUpdateResults.Text = "Image filename length must be 50 characters or less. Please rename the file and try again.";
                    }
                }
            }
            else
            {
                lblUpdateResults.Text = "Image import unsuccessful. No image specified.";
            }
        }
开发者ID:ezimaxtechnologies,项目名称:ASP.Net,代码行数:66,代码来源:StaffIdentification_Edit.aspx.cs

示例9: SaveFile

 /// <summary>
 /// Guarda el archivo
 /// </summary>
 /// <param name="uploadedFile">Archivo a guardar</param>
 /// <returns></returns>
 private string SaveFile(UploadedFile uploadedFile)
 {
     string fileName = string.Empty;
     if (uploadedFile.IsValid)
     {
         fileName = string.Format("{0}{1}", Server.MapPath("~/ui/ExcelFiles/"), uploadedFile.FileName);
         if (File.Exists(fileName))
             File.Delete(fileName);
         uploadedFile.SaveAs(fileName);
         Session.Add("filename", fileName);
     }
     return uploadedFile.FileName;
 }
开发者ID:ramirobr,项目名称:DQBase,代码行数:18,代码来源:Interfase.aspx.cs

示例10: saveFiles

 public int saveFiles(UploadedFile fs, string folderType, int clientID, int actionBy, int userID, int webinarID)
 {
     int DocID = 0;
     string fname = "";
     try
     {
         DocumentBE objDcoumentBE = new DocumentBE();
         DocumentDA objDocumentDA = new DocumentDA();
         if (fs.FileName != "")
         {
             fname = System.IO.Path.GetFileName(fs.FileName);
             switch (folderType.ToUpper())
             {
                 case "PROFILE":
                     fs.SaveAs(Constant.DocRepoClient + clientID.ToString() + "\\Profile\\" + fname);
                     break;
                 case "LOGO":
                     fs.SaveAs(Constant.DocRepoClient + clientID.ToString() + "\\Logo\\" + fname);
                     break;
                 case "BANNER":
                     fs.SaveAs(Constant.DocRepoClient + clientID.ToString() + "\\Logo\\" + fname);
                     break;
                 case "PRESENTATION":
                     fs.SaveAs(Constant.DocRepoClient + clientID.ToString() + "\\WebinarDocs\\" + fname);
                     break;
                 case "SS":
                     fs.SaveAs(Constant.DocRepoClient + clientID.ToString() + "\\SS\\" + fname);
                     break;
                 case "TEMP":
                     fs.SaveAs(Constant.DocRepoClient + clientID.ToString() + "\\Temp\\" + fname);
                     break;
             }
             objDcoumentBE.DocumentID = 0;
             objDcoumentBE.ClientID = clientID;
             objDcoumentBE.Category = folderType;
             objDcoumentBE.OrginalFileName = fname; //fs.GetName();
             objDcoumentBE.SavedFileName = fname; //fs.GetName();
             objDcoumentBE.InsertedBy = actionBy;
             objDcoumentBE.PresenterID = userID;
             objDcoumentBE.WebinarID = webinarID;
             DocID = objDocumentDA.SaveDocumentDA(objDcoumentBE, userID, webinarID);
         }
     }
     catch (Exception ex)
     {
         objUtil.RecordLogToFS("DocAccess-saveFiles:" + ex.Message);
     }
     return DocID;
 }
开发者ID:selva-osai,项目名称:scheduler,代码行数:49,代码来源:DocAccess.cs

示例11: GetCSVReader

 /// <summary>
 /// Gets the CSV reader.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <param name="importId">The import id.</param>
 /// <returns></returns>
 private ImportCSVReader GetCSVReader(UploadedFile file, string importId)
 {
     try
     {
         string fileName = importId + ".csv";
         string path = ImportService.GetImportProcessPath() + fileName;
         ImportService.DeleteImportFile(path);
         //file.MoveTo(path);
         file.SaveAs(path);
         ImportCSVReader reader = new ImportCSVReader(path);
         return reader;
     }
     catch (Exception ex)
     {
         log.Error("The call to StepSelectFile.GetCSVReader() failed", ex);
         lblError.Text = GetLocalResourceObject("error_InvalidImportPath").ToString();
         divError.Style.Add(HtmlTextWriterStyle.Display, "inline");
         divMainContent.Style.Add(HtmlTextWriterStyle.Display, "none");
         (Parent.Parent.FindControl("StartNavigationTemplateContainerID").FindControl("cmdStartButton")).Visible = false;
         throw new UserObservableApplicationException(GetLocalResourceObject("error_InvalidImportPath").ToString(), ex);
     }
 }
开发者ID:ssommerfeldt,项目名称:TAC_EAB,代码行数:28,代码来源:StepSelectFile.ascx.cs

示例12: SavePostedFile

        private void SavePostedFile(UploadedFile uploadedFile)
        {
            if (!uploadedFile.IsValid)
                return ;

            var fileOriginalName = uploadedFile.FileName;

            int index;
                for (index = 0; index < UploadControlBudges.UploadedFiles.Length; index++)
                {
                    if (UploadControlBudges.UploadedFiles[index].FileName == fileOriginalName)
                    {
                        break;
                    }
                }
            if (index == 0)
            {
                _fileGroupId = _dal.RegisterNewBadgesFileGroup(tbBadgeGroupName.Text, tbMessage.Text, TbDescription.Text, cbImageType.Text, Convert.ToInt32(cbGrantRule.SelectedItem.Value));
            }

            var guid = Guid.NewGuid();

            string fileName = Path.Combine(MapPath(UploadDirectory), guid.ToString() + ".png");
            uploadedFile.SaveAs(fileName, true);
            _dal.RegisterNewBadgeInFileGroup(_fileGroupId, guid, index);
        }
开发者ID:Letractively,项目名称:dc-gamification,代码行数:26,代码来源:ManageBadges.ascx.cs


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