|
-
Jan 7th, 2003, 10:11 AM
#1
Thread Starter
Frenzied Member
searching a string [RESOLVED]
I'm using <input type=file> to let a user select a file for upload. I only want to let them select a .pdf document. I'm not sure how filter out the file dialog using a <html> control, so I was thinking about doing a string search on the file chosen. Is there a way to check if it's a .pdf?
Last edited by EyeTalion; Jan 9th, 2003 at 03:18 AM.
-
Jan 8th, 2003, 06:17 PM
#2
Addicted Member
Code:
sExt = System.IO.Path.GetExtension("test.pdf")
if sExt = "pdf" then...
-Daryl
"Two More Rolls of Duct tape, and the world is mine!"
VB.NET Guru
-
Jan 8th, 2003, 11:00 PM
#3
Fanatic Member
I suppose that will work, however with the file uploads in asp.net, there's an even better way to test file type/extension....
lets say your file input is called myFile:
<input type="file" Runat="server" id="myFile">
Use:
VB Code:
myFile.PostedFile.ContentType
i'm not sure what it will return for a PDF, so make a test page that has a file input and upload a pdf file then just response.write(myFile.PostedFile.ContentType)... that should return a string of the content type... this should look at the file itself, and it will make sure that the file is the proper type, not just the extension...
-
Jan 9th, 2003, 03:18 AM
#4
Thread Starter
Frenzied Member
hey guys I used:
string strFilename = fileInput.PostedFile.FileName;
if(strFileName.EndsWith(".pdf")
{
}
works fine....thanks for the input.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|