validate-upload file

Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Dec 2004
Posts: 6
Reputation: fmardani is an unknown quantity at this point 
Solved Threads: 0
fmardani fmardani is offline Offline
Newbie Poster

validate-upload file

 
0
  #1
Apr 26th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 36
Reputation: web developer is an unknown quantity at this point 
Solved Threads: 0
web developer's Avatar
web developer web developer is offline Offline
Light Poster

Re: validate-upload file

 
0
  #2
Apr 27th, 2006
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.
Life Is A Big Code
Rushdy Ibrahim
Egypt
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC