Click here to Skip to main content
15,174,232 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to use the stored string location(path) in a sql server table to display in a table grid.

Please give examples or link to suggest solutions.

thanks.
Posted
Comments
postonoh 9-Apr-12 14:46pm
   
I understand how to you directory.getfiles. I save upload fines to a dynamic string path that is stored in a SQL server database. I need to get the path that is was stored to upload and download files form their location.

It depends on the location. If you are using the client-server model, and the files are located on some server, not on the client's host, you need some service which would deliver the files on request. So, on the server host you need to run FTP server, HTTP server (a Web service or a Web site, a Web application) or some custom service capable of delivering files. Is this is what you have, you can get files programmatically using the class System.Net.FtpWebRequest or System.Net.HttpWebRequest, respectively. Please see:
http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx[^],
http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx[^],
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[^].

The similar situation if is you are using a file service based model, but in this case you already have some file service; so you would not need to do anything special. And if you are using it all on one computer, the situation is trivial; so I don't think you were asking about that.

—SA
   
Comments
postonoh 9-Apr-12 14:46pm
   
I understand how to you directory.getfiles. I save upload fines to a dynamic string path that is stored in a SQL server database. I need to get the path that is was stored to upload and download files form their location.
postonoh 10-Apr-12 10:37am
   
This does not address my question. I need to query the column that has the string location of the files and display file in a grid.
Sergey Alexandrovich Kryukov 12-Apr-12 12:32pm
   
What part of this task is a problem? Do you want to display the file name in the grid, or some file content? What's the problem here?
--SA
My answer thanks everyone.

C#
public List<mycombinedquerymodel> Files(int? id)
        {


             var uploads = (from u in _db.Patients
                           where u.PatientsId == id
                           select u.FilesUrl).FirstOrDefault();


             if (uploads != null)
             {
                  var dir = new DirectoryInfo(uploads);

                  IEnumerable<fileinfo> filelist = dir.EnumerateFiles("*.*", SearchOption.AllDirectories);

                  var query = (from file in filelist
                               where file.Length > 0
                               let fileName = file.Name
                               select new MyCombinedQueryModel
                                           {
                                                FileName = file.Name
                                           }).ToList();


                  return query;
             }
             return null;
        }
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900