0

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

2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by web developer
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.