944,156 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 5412
  • ASP.NET RSS
Apr 26th, 2006
0

validate-upload file

Expand Post »
Hi,
There is a requirement to be able to upload files using a website (asp.net 2.0) . There should be a kind of validation on these files before the upload is allowed. What I am not sure of is how can I do any kind of validation on the files before the upload? For example if a file of type excel or .txt is to be uploaded, the website has to first check to see if there are certain data in the file... then if all ok the upload is allowed.
Thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fmardani is offline Offline
6 posts
since Dec 2004
Apr 27th, 2006
0

Re: validate-upload file

Hi
You may used a web control named file control in asp.net 2.0 that is better than the html control file in the asp.net 1.0 , so u can use its data by the property File1.PostedFile
which File1 is the control .
if you want to get the lenght of the posted file u can use
File1.PostedFile.ContentLength
To return the bytes exist in the file use the following code :
int len=File1.PostedFile.ContentLength;
byte[] bData=new byte[len];
File1.PostedFile.InputStream.Read(bData,0,len);

Now the array bData is full of bytes in the file , so u can stream it and put check u want.
Note: If u didn't use the web control and used the html control
right click on it and check run as server control and complete the previous steps.
Reputation Points: 10
Solved Threads: 0
Light Poster
web developer is offline Offline
36 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Browser Close Button
Next Thread in ASP.NET Forum Timeline: Clustered Cache in ASP.NET





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC