File Download: How to check if a file is selected using the multipart file
source link: https://www.codesd.com/item/file-download-how-to-check-if-a-file-is-selected-using-the-multipart-file.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
File Download: How to check if a file is selected using the multipart file
I'm developing a web api to upload file using Multipart file-upload following the instructions here: https://www.asp.net/web-api/overview/advanced/sending-html-form-data-part-2 . I wounder if there is any way to check if any file is selected or not. Yes the length can be checked if it is zero but what if an empty file was actually uploaded.
Yes you can. You have already mentioned the length property, you can also check the expected file extension, e.g., .jpeg, jpg, .png, .gif, .swf, .pdf, .doc, .docx etc.
When the user uploads the file, get the file path
public string GetFileExtension(){
string fileName = Server.MapPath(FileUpload1.FileName);
string extension = Path.GetExtension(fileName);
return extension;
}
//Validate
public bool IsValidFileExtension(string fileExtension)
{
switch(fileExtension)
{
case ".jpeg":
return true;
break;
case ".jpeg":
return true;
break;
default:
return false;
}
return false;
}
//Validate
string fileExtension = GetFileExtension(fileExtension);
bool IsValidFile = IsValidFileExtension(fileExtension);
Related Articles
How to check user permissions on SharePoint 2010 using the client object model?
How to check a value in a form using the Google Apps script
How to check my project folder from svn using the command line without displaying the dialog box
How to check if a specific port listens using the Python script?
How do I set an option as selected using the Selenium WebDriver (selenium 2.0) software to ruby
How to check whether two time values are on the same date
Detect whether the file was selected using the CodeIgniter input class
How to check if an element already exists in the array
How to check if there are only numbers in the chain
How to know which item is currently selected in the Combo Box drop-down menu
how to allow connection with e-mail by using the Asp signup component
how to identify if multiple indexes are selected in the listbox control in c # winforms?
How can I implement CRUD access with actions using the same view?
How to get an ASP.NET WebSite to use the right assembly (file reference instead of path / gac)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK