Look to see if a certain file exist in from button click

Discussion in 'ASP .Net' started by pvong, Oct 1, 2009.

  1. pvong

    pvong Guest

    I'm a newbie. Trying to do this in VB.NET

    On my server, I have a directory called c:\db\files\ and I have a whole
    bunch of pdf files in here. I want to do an onclick where the server checks
    to see if any of the files starts with the word "sharp". So I will have
    lots of files, but some files will look like this:

    sharp123.pdf
    sharp321.pdf
    sharp987.pdf

    I just want to look for the beginning of the word "sharp". If it finds a
    file starting with that, then I want it to do whatever. The directory is on
    the same server as my IIS and runing the site.

    Thanks!
     
    pvong, Oct 1, 2009
    #1
    1. Advertising

  2. pvong

    Scott M. Guest

    Visual Studio 2005 or 2008 has a code snippet for the first part of your
    problem. Looping through the results after that is easy:

    Dim files As ReadOnlyCollection(Of String)
    files = My.Computer.FileSystem.FindInFiles("c:\db\files", "sharp", True,
    FileIO.SearchOption.SearchTopLevelOnly, "*.pdf")

    If files.Count > 1 Then
    For Each file In files
    'Work with file that contains "sharp"
    Next
    End If

    Scott M.


    "pvong" <vonger@*dot*com> wrote in message
    news:...
    > I'm a newbie. Trying to do this in VB.NET
    >
    > On my server, I have a directory called c:\db\files\ and I have a whole
    > bunch of pdf files in here. I want to do an onclick where the server
    > checks to see if any of the files starts with the word "sharp". So I will
    > have lots of files, but some files will look like this:
    >
    > sharp123.pdf
    > sharp321.pdf
    > sharp987.pdf
    >
    > I just want to look for the beginning of the word "sharp". If it finds a
    > file starting with that, then I want it to do whatever. The directory is
    > on the same server as my IIS and runing the site.
    >
    > Thanks!
    >
    >
     
    Scott M., Oct 1, 2009
    #2
    1. Advertising

  3. "pvong" <vonger@*dot*com> wrote in
    news::

    > I'm a newbie. Trying to do this in VB.NET
    >
    > On my server, I have a directory called c:\db\files\ and I have a
    > whole bunch of pdf files in here. I want to do an onclick where the
    > server checks to see if any of the files starts with the word "sharp".
    > So I will have lots of files, but some files will look like this:
    >
    > sharp123.pdf
    > sharp321.pdf
    > sharp987.pdf
    >
    > I just want to look for the beginning of the word "sharp". If it
    > finds a file starting with that, then I want it to do whatever. The
    > directory is on the same server as my IIS and runing the site.


    One hurdle to overcome here is the files are not in the web directories.
    you can do this by creating a virtual directory to search the files
    from. Otherwise, you will have to reduce some security setting to reach
    the "outside" folder.

    As for figuring out the files, you can loop through:

    DirectoryInfo dir = new DirectoryInfo(filePath);
    Regex regex = new Regex("^sharp");

    foreach(FileInfo file in dir.GetFiles())
    {
    if(Regex.Match(file.Name).Success)
    {
    //file begins with sharp
    }
    }

    You may have to vary the code a bit to get exactly what you want.
    Outputting a PDF is a matter of streaming the bytes with a MIME type of
    application/pdf.

    Peace and Grace,

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
     
    Gregory A. Beamer, Oct 1, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    925
    Purvi T
    Oct 19, 2004
  2. Dave
    Replies:
    3
    Views:
    3,153
  3. Amy
    Replies:
    0
    Views:
    1,029
  4. Gregory A. Beamer

    Re: Look for a certain file name

    Gregory A. Beamer, Oct 9, 2009, in forum: ASP .Net
    Replies:
    5
    Views:
    379
    Gregory A. Beamer
    Oct 9, 2009
  5. kazaam
    Replies:
    3
    Views:
    156
    kazaam
    Aug 26, 2007
Loading...

Share This Page