Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc HttpPostedFileBase getting file extension

public string ContructOrganizationNameLogo(HttpPostedFileBase upload, string OrganizationName, int OrganizationID,string LangName)     {          var UploadedfileName = Path.GetFileName(upload.FileName);         string type = upload.ContentType;     } 

I want to get the extension of the file to dynamically generate the name of the file.One way i will use to split the type. but can i use HttpPostedFileBase object to get the extension in the clean way?

like image 236
maztt Avatar asked May 28 '10 13:05

maztt


People also ask

How can I get file extension in MVC?

string extension = Path. GetExtension(upload. FileName);

What is the extension of a ASP.NET file?

ASP.NET pages have the extension . aspx, and are normally written in VB (Visual Basic) or C# (C sharp). User controls in ASP.NET can be written in different languages, including C++ and Java.

What is the extension of the C# ASP.NET MVC Razor view file?

The Razor syntax consists of Razor markup, C#, and HTML. Files containing Razor generally have a . cshtml file extension.

How do I validate a file type in C#?

bool CheckFileType(string fileName) { string ext = Path. GetExtension(fileName); switch (ext. ToLower()) { case ". gif": return true; case ".


1 Answers

Like this:

string extension = Path.GetExtension(upload.FileName); 

This will include a leading ..

Note that the you should not assume that the extension is correct.

like image 134
SLaks Avatar answered Oct 24 '22 20:10

SLaks