本文整理汇总了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'/> Your video was successfully uploaded ";
}
else
{
litCompleted.Text = "<img src='images/na.gif'/> Your video must be at least 2 seconds long";
}
}
else
{
if (ValidExtention)
litCompleted.Text = "<img src='images/na.gif'/> Videos with the extention <strong>" + Ext + "</strong> arent supported";
else
litCompleted.Text = "<img src='images/na.gif'/> 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");
}
}
示例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);
}
示例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.";
}
}