Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Look to see if a certain file exist in from button click

Reply
Thread Tools

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

 
 
pvong
Guest
Posts: n/a
 
      10-01-2009
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!


 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      10-01-2009
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!
>
>



 
Reply With Quote
 
 
 
 
Gregory A. Beamer
Guest
Posts: n/a
 
      10-01-2009
"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! |
*******************************************
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding one certain line in a file is easy but how to look forheadlines and something just under this certain headline? kazaam Ruby 3 08-26-2007 03:34 PM
How to fire both event button click and textchanged when button is click and text is changed Amy ASP .Net 0 06-01-2006 02:33 PM
image button click event fires before click event of button Purvi T ASP .Net 0 10-19-2004 06:19 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Building Controls 1 05-28-2004 06:23 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57