How to identify the original file type and restrict the file uploading while using file upload control

 Hi asp.net ,

 

I am uploading a file using FileUpload control in asp.net using vb.net.I wrote the code to upload only PDF files.

 the user can change the extension and change to PDF . 

I have to check is the file original PDF or not then i have to upload the PDF files only .

 

How to do this ?? 

0
for1206
9/7/2008 11:04:59 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

3 Replies
1468 Views

Similar Articles

[PageSpeed] 18

Hi, Check the file Mime type for "application/pdf" by looking at the:  

FileUpload1.PostedFile.ContentType
 
Regards
Smcoxon

No Gem is ever polished without some friction.
0
smcoxon
9/7/2008 7:02:02 PM

Hi smcoxon , Thanks For Replying ,But i found that there is no use using

PostedFile.ContentType="application/pdf" .It is also checking the extension is pdf or not ,Which can be done by  client script.

For example , There is an mpg file . I am giving access to upload only pdf file in the application.

He can change the extension and send it as pdf file. Now the actual thing here is ,

I have to find the internal content whether it is orginally generated by PDF or not .then i have to upload the actual PDF file .

 

Thanks ,

for1206.

0
for1206
9/8/2008 5:07:23 AM

Hi,

I think you need to upload to the server all files with an extension .PDF. Then on the server side, you can read the the first two bypes of the file because I test to prove that the first two bytes of all PDF files are identical, whereas a fake file with .pdf extension will be different with the first two bypes. Thereby by this we can determine a file whether or not is one of .pdf type.

The following is my testing code. Please refer to it:

   

           
            System.IO.BinaryReader binReader = new System.IO.BinaryReader(filepath, System.IO.FileMode.Open));

            byte[] testArray = new byte[2];
            int count = binReader.Read(testArray, 0, 2);
            string str = null;
                if (count != 0)
                {
                    str = binReader.ReadByte().ToString();
                    str = str + binReader.ReadByte().ToString() + binReader.ReadByte().ToString();
                  
                }

// We can see the value of the first two bytes are identical.
                Response.Write(str);
                binReader.Close();
 
0
ASPNetEngineer
9/13/2008 8:07:36 AM
Reply:

Similar Artilces:

Is there any limitation of file types that file upload control can be used to upload?
I am working on a content management system which requires me to upload WebEx recording files (.wrf) through file upload control. But I am getting "internet explorer cannot display the webpage" error. It worked with other files types as txt, doc, xls, pdf, jpg, gif etc. Is it related to any security issue or just a bug with the file upload control?  Thank you. The file upload control doesn't have any file type limitations that I'm aware of, but it does have some size constraints.  By default, ASP.NET is configured to not accept any file's larger than 4...

web.pb and file upload (using type=file)
Hello all. Has anyone successfully _processed_ a form with a "input type = file" based file upload via a web.pb function call? I certainly won't work by declaring an argument as a blob and accepting it that way...unless there is some post call processing I'm missing.. I'm pretty sure it is a multi-part data stream problem. Anyone have a function out there to accept the form? Thanks in advance!! I'll owe you one. -W -- William Rompala J.P. Morgan -- Lose the X before william in email address to send mail ...

Add link buttons to each file uploaded using File upload control
Hi,   In my application I have one file upload control. When the user selectes a file to upload and when he clicks on Attach button I need to show him the file name of the file he selected to upload and also show the Remove link button after the file name. In this case I need to generate link button dynamically. I wrote a code like the following:protected void btnAttach_ServerClick(object sender, EventArgs e) {string strFileName = MyFile.PostedFile.FileName;string c = System.IO.Path.GetFileName(strFileName); listBoxAttachedFiles.Items.Add(c);LinkButton b = new LinkButton(); b.Te...

File Upload
Hi,  I am using the file upload code at the link below to allows users to upgrade multiple files into  a storage area. http://dotnetslackers.com/community/blogs/basharkokash/archive/2007/09/11/Test.aspx My question is how do I identify which files belong to which user?? On my site i am using ASP membership and before uploading files users must logg on. Does this mean I can use the UserID to identify them or is there another simple wayI I have the file upload in a simple wizard form. Also i am coding in C sharp   Thank you Amereto   You can use the logged...

Deleting A File Uploaded Through File Upload Control
Hello, I have a form which allows a user to upload a file to a virtual drive on our server using the following code: fileInvoice.SaveAs(ConfigurationManager.AppSettings.Get("DocumentPath") + strFileName); //Document Path is defined in the web.config file How can I safely allow a form on a web page to delete the file if they know the exact name of the file. I don't want them to be able to do a wildcard match like test* thanks in advance, mitch  Peace be on you brother, so you want to safely delete the file which the name you know. OK I consider that the name ...

Upload all files in folder with file upload control
H i I'm trying to upload all files to a wesite that is in a specific local folder. My code workes fine when I run it locally but when I upload it it fails. I think it looks for the files to upload on the web server and thus cannot find it.  1 Dim files() As String 2 folderExists = System.IO.Directory.Exists(foldername) 3 If folderExists = False Then 4 Label1.Text = "Folder does not exist. Did you enter a folder name or just a file name ?" 5 Exit sub 6 End If 7 files = System.IO.Directory.GetFiles(foldername) 8 For...

File upload "restricted file type" using FCKeditor
Hello! I'm trying to hyperlink some text in a regular html/text module using FCKeditor...I highlight the text, click on the little link icon...go through the prompts, etc.  The file that I'm trying to upload has a .avi extension.  I get the following error when trying to "Upload Selected File". The File D:\DotNetNuke\Portals\25\filename.avi Is A Restricted File Type. Valid File Types Include ( *. swf, *.jpg, *.jpeg, *.jpe, *.gif, *.bmp, *.png, *.doc, *.xls, *.ppt, *.pdf, *.txt, *.xml, *.xsl, *.css, *.zip ). Please Contact Your Hosting Provider If You Need To Upl...

How Do I Enable A File Upload Control When Another File Upload Control Has A Value?
Hi There,Thanks you for taking the time to read this post.  I am quite new to programming and have searched the net and experimented with my own code but not been able to get it to work yet.I am creating a simple CMS for a friends site and my friend wants to be able to upload 9 images per page.I have created an asp.net form with 9 file upload controls.  I want 1 control to be enabled by default and the other 8 controls disabled until the previous control has a value.  I have set the default setting in visual studio without any problem.My first thought was to double cli...

Posting filepath in file upload control in .NET to the next page and uploading the file from second page
In our application (using C# .NET) there is a form with file upload options. After filling up the form details, the summary of the details need to be shown in the next page before committing the information into the database. Right now, Server.Control is used to transfer the contents to the next page and the form details are retrieved using Request.Form["control id"]. But this is not working for File upload control alone.File upload can not be done in the first page itself, as the foreign key in File upload table gets updated only in second page after confirmation. Therefore, is th...

Processes file content before upload (from file upload form)
Hello I have a web aplication that needs to process file content (client side) before uploading them to server. May be I have to use file upload form and somehow read files and sign them on submit event I'm not sure how (and can I) do this in Firefox extension? I prefer to use browser functionality for file upload rather than make my own HTTP connection from my extension. I also prefer not to write any user interface. On 4/7/10 7:27 AM, Юлиян wrote: > I have a web aplication that needs to process file content (client > side) before uploading them to server. htt...

Upload file from remote Computer using File Upload
Hi,     How to upload file from remote computer. Can i browse it thruough the File Upload control ?    Please help?     RamarjunK:Hi,     How to upload file from remote computer. Can i browse it thruough the File Upload control ?    Please help?  you can. when the file open dialog box comes, choose my network places, select the corrosponging share, specify the credentials.  then choose the file.you haven't do any thing special, coding is same .Give a man a fish and you feed him for a day. Teach a man to fish a...

Is there a way to automate uploading file in a web page using html file input control?
I used a form with a web browser control on it to automate the process of connecting to a website entering the login and password and finish the process of uploading a file.As you navigate to the upload page i can't get the input file control to work automatically because the value property is read only and here is the code HtmlDocument loginPage = wb.Documanet;loginPage.All["file1" ].SetAttributes("value", @"C:\A\A.txt");              //this doesn't work Your help is appreciated. Mark as an answer if it helps. ...

Uploading Files without using File control
Hi Everyone, I'm in need of a feature where i need to upload a file without using File control. Anyone have pointers to go about it ? I've already gone through this tutorial: http://www.15seconds.com/issue/010522.htmbut when i try to run the code it gives me the error on window 2000 PC:"Safety settings on this computer prohibit accessing a data source on another domain."even though security setting set to "Low". And on XP machine i get the error:"Can't create automation server" (or something like that not entirely sure)My actual requirement is to upload a file using AJAX.Help will be gr...

file uploader save file on server and in database and upload this file on client
hi,i have a file uploader control user can attach files (.rar, .zip, etc) and store file folder and path in database. and another user can click of attach link and can download that file. how can i do this please solve out this problem. you can find your problem solution in this link and you can store the file name in your database server.http://www.aspnettutorials.com/tutorials/network/net-fileupload-aspnet2-csharp.aspxPlease Mark as Answred If This Blog has Helped You.RegardsMitesh Darjihttp://www.indianic.comhttp://www.mitatdotnet.blogspot.com As always there are many ways and which ...

Web resources about - How to identify the original file type and restrict the file uploading while using file upload control - asp.net.web-forms

Uploading and downloading - Wikipedia, the free encyclopedia
Examples of a remote system from which a download might be performed include a web server , FTP server, email server, or other similar systems. ...

Facebook Lets You Tag Photos While They're Uploading
Facebook now lets you add tags to photos before they're finished uploading.

Facebook for iPhone 3.0 to Include Video Uploading for 3GS Owners
We’ve heard a lot of people say the iPhone’s built-in support for YouTube video uploading is going to make a huge impact on the number of people ...

Defence bureaucrat pleads guilty to uploading secret document online
... embarrassing security breach with "Five Eyes" intelligence document. A former junior Defence bureaucrat has pleaded guilty to uploading ...

Uploading Bautista bat flip GIFs could get you sued under TPP, copyright activists warn
Copyright activists say Canadians could face lawsuits, fines or worse for ripping the latest Justin Bieber CD or uploading an animated GIF of ...

Xiaomi apologizes for uploading address book data from smartphones without permission
Former Android head and Xiaomi VP Hugo Barra has apologized to owners of its smartphones for "any concern caused" by collecting contact data ...

Senator calls for FTC investigation of Apple and Google over stealth photo uploading capabilities
Is this how we’ll have to open apps in the future? When we broke the news that iOS (and later Android) apps could upload your photo library (along ...

YouTubers Now Uploading Over 35 Hours Of Video Per Minute!
This week YouTube's got some big news! YouTubers are now uploading over 35 hours of video per minute, up from 24 hours a minute in March.

Google Play Books updated with new design, PDF and EPUB uploading
Caught up in all of the hullabaloo around the keynote, Google Play Books received a notable update in the Play Store to not only bring new UI ...

Twitter rolling out group messaging, 30-second video uploading
Fast Company Twitter rolling out group messaging, 30-second video uploading Android Community Different social networks are doing everything ...

Resources last updated: 12/23/2015 10:22:59 PM