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


C# UploadedFile.GetExtension方法代码示例

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


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

示例1: ProcessVideo

    //private void LooongMethodWhichUpdatesTheProgressContext(UploadedFile file)
    //{
    //    const int total = 100;

    //    RadProgressContext progress = RadProgressContext.Current;

    //    for (int i = 0; i < total; i++)
    //    {
    //        progress["PrimaryTotal"] = total.ToString();
    //        progress["PrimaryValue"] = i.ToString();
    //        progress["PrimaryPercent"] = i.ToString();
    //        progress["CurrentOperationText"] = file.GetName() + " is being processed...";

    //        if (!Response.IsClientConnected)
    //        {
    //            //Cancel button was clicked or the browser was closed, so stop processing
    //            break;
    //        }

    //        //Stall the current thread for 0.1 seconds
    //        System.Threading.Thread.Sleep(100);
    //    }
    //}

    public void ProcessVideo(UploadedFile VideoFile)
    {
        litCompleted.Text = "";
        try
        {
            member = (Member)Session["Member"];
            bool ValidExtention = true;
            string VideoTitle = string.Empty;
            string Ext = string.Empty;

            Video video = new Video();

            video.Title = (txtTitle.Text != "") ? txtTitle.Text : "New video";
            video.Description = (txtCaption.Text != "") ? txtCaption.Text : "No Description"; 

            try
            {
                Ext = VideoFile.GetExtension();
            }
            catch
            {
                Ext = "xxx";
                ValidExtention = false;
            }

            Ext = Ext.Replace(".", "");

            // upload the flv
            if (IsVideo(Ext))
            {
                if (VideoFile.ContentLength > 150000)
                {
                    Video.QueueVideoForEncoding(video, VideoFile.InputStream, Ext, member, VideoTitle);
                    litCompleted.Text = "<script>parent.location.href='MyVideoGallery.aspx?p=1';</script><img src='images/check.gif'/>&nbsp;&nbsp; Your video was successfully uploaded ";
                }
                else
                {
                    litCompleted.Text = "<img src='images/na.gif'/>&nbsp;&nbsp;Your video must be at least 2 seconds long";
                }
            }
            else
            {
                if (ValidExtention)
                    litCompleted.Text = "<img src='images/na.gif'/>&nbsp;&nbsp;Videos with the extention <strong>" + Ext + "</strong> arent supported";
                else
                    litCompleted.Text = "<img src='images/na.gif'/>&nbsp;&nbsp;Videos files must have an extention name. For example: .avi or .mov";
            }
        }
        catch(Exception ex)
        {
            string MachineName = Environment.MachineName;
            Next2Friends.Data.Trace.Tracer(ex.ToString(), "RadVideoUpload");
        }
    }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:78,代码来源:UploadVideo2.aspx.cs

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

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


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