2

File Download: How to check if a file is selected using the multipart file

 2 years ago
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

advertisements

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?

The following code always returns false (which is incorrect, as the user has Full Control permission at the site level): Site site; BasePermissions permissionMask; ClientResult<bool> result; permissionMask = new BasePermissions(); permissionMask.Set

How to check a value in a form using the Google Apps script

I am working on a "deploy as a web app - Google Apps Script". The script uses the 'html service'. My sample script does write data to a Google Sheet but I hope to do more with your help. I want to check to make sure the email value contains a va

How to check my project folder from svn using the command line without displaying the dialog box

I want to checkout my project folder from svn using command line in batch file and I want to automate that process. For that I don't want the dialog box which appears after the checkout command showing the checkout path and all. How can I do this?Tor

How to check if a specific port listens using the Python script?

I want to check if api and app are running before running tests on them. I know I can get a list of open ports in CLI using sudo lsof -iTCP -sTCP:LISTEN -n -P But I want to write a python script to do so. Any ideas on what library should I use or how

How do I set an option as selected using the Selenium WebDriver (selenium 2.0) software to ruby

I am trying to get familiar with the new ruby selenium-webdriver as it appears more intuitive mostly than the previous version of selenium and the ruby driver that went with it. Also, i had trouble getting the old selenium to work with ruby 1.9.1 in

How to check whether two time values ​​are on the same date

How to check two times if they are in the same date or not ? For example first- 08:00:00 second- 16:00:00 in the same date . first- 20:00:00 second- 04:00:00 two different datesYou can use CASE EXPRESSION : SELECT CASE WHEN t.first > t.second THEN 'T

Detect whether the file was selected using the CodeIgniter input class

I'm trying to detect if a file was selected using the CodeIgniter input class: Using the Form Helper to output an upload input in my view: echo form_upload('image', isset($ad)?$ad['image']:"", 'placeholder="Image" title="Please Ch

How to check if an element already exists in the array

i am sending value from one page to another,i want to store the values which i hav sent,& then want to compare the value which i am sending with the one which i hav already sent,i.e the saved value.while storing the values into an arrayin persistent

How to check if there are only numbers in the chain

how to check if there is only numbers in the string? I want to skip some code with goto if there's only numbers in the string. Thanks try i := StrToInt( str ); except { str is NOT an integer } end;

How to know which item is currently selected in the Combo Box drop-down menu

How to know which item is currently selected in the Combo Box Popup. So that the Combo Box can be updated while the navigation happens inside the Popup. Note: Need to update it though the Combo Box's popup is still open. Like the below image, Try set

how to allow connection with e-mail by using the Asp signup component

as the title says how do o allow users to sign in using the email they specified when they registered. using asp 3.5 , both the login and signup are the ones that are built-in visual studio. also is there a way to remove the secret question and answe

how to identify if multiple indexes are selected in the listbox control in c # winforms?

I am developing an application and I have a requirement to place the fields on front end just like take checkbox. If the user selected particular fields on the checkbox, then based on the selection I will generate crystal report from sql database. So

How can I implement CRUD access with actions using the same view?

How do I implement CRUD access with actions using the same view? class UserController : Controller { [ActionName("User")] [HttpGet] public ActionResult GetUser() {/* ... */} [ActionName("User")] [HttpPost] public ActionResult PostUser(

How to get an ASP.NET WebSite to use the right assembly (file reference instead of path / gac)

I recently started using Jenkins to ease application Development. I have an Asp.net website that I am trying to deploy using it. Details about the build: The project is retreived from Visual Source Safe using Jenkins. Is is then compiled using msbuil

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK