Results 1 to 4 of 4

Thread: searching a string [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    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.

  2. #2
    Addicted Member Dmyze's Avatar
    Join Date
    Mar 2002
    Location
    Seattle
    Posts
    160
    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

  3. #3
    Fanatic Member Redth's Avatar
    Join Date
    May 2001
    Location
    Ontario, Canada
    Posts
    551
    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:
    1. 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...

  4. #4

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    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
  •  



Click Here to Expand Forum to Full Width