insert a unc path to db

G

Guest

How can I do the following in C# .NET:

In a directory somewhere on the network I have many .JPG or .PDF files. I
need a way to browse to that location on the network, select the directory or
the first file in that directory and then have the full UNC path of all the
files inserted into a SQL2k db, in a field named 'ThePath'

the unc filename should looks like this:

\\ServerName\DirectoryName\fileName.jpg or .pdf

Thanks

Paul
 
W

W.G. Ryan eMVP

First retireive it from the db using ExcecuteScalar - afterward you can just
use

DirectoryInfo di = new DirectoryInfo(ReturnValueFromDb);
foreach(FileInfo fi in di.GetFiles()){
}
 
G

Guest

I'm a little unclear about 'First retireive it from the db using
ExcecuteScalar'

There is nothing in the db yet, I first need to get the full path of where
the file names are and then insert that into the db.
 
S

Steven Cheng[MSFT]

Hi Ryan,

Do you means you want to programly get a reference to a certain UNC shared
folder via its path and then enumerate all the files under that folder and
store all those files' fullpath into db?
If so, I think we can use the System.IO.DirectoryInfo class to get a UNC
folder's info (as long as that folder has shared with the appropriate
privilage).

For example:
the following code print out all the files's Full path under a give UNC
shared dir.

static void EnumUNCFolder(string uncpath)
{
DirectoryInfo di = new DirectoryInfo(uncpath);

if(di != null)
{
FileInfo[] files = di.GetFiles();

Console.WriteLine(di.FullName + " " + di.CreationTimeUtc);
for(int i=0;i<files.Length;i++)
{
Console.WriteLine("@ " + files.Name + " " + files.CreationTimeUtc);

}
}
}

we can use it like EnumUNCFolder(@"\\servername\shareddir")

HOpe helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top