Search code examples
asp.netajaxcontroltoolkit

In asyncfileupload check content type


In asyncfileupload i want to check zip and rar i try following code

    protected void fileUploadComplete(object sender, AsyncFileUploadEventArgs e)
    {
        string type = fileUpload1.ContentType;

    }

When i am upload zip or rar file in type variable when i am debug this i get type like "application/octet-stream". How can i check zip or rar file. i can check using javascript but after that how can i upload on server if i am use javascript for checking.


Solution

  • Try this:

    HttpPostedFile fileupload1 = context.Request.Files[0];
    System.IO.FileInfo fileupload1Info = new System.IO.FileInfo(up.FileName);
    string ext = fileupload1Info.Extension;
    if(ext!='.zip' || ext!='.rar'){
          //your logic
     }