当位置字符串存储在sql server表中时,如何从文件位置检索文件. [英] How to retrieve files from file location when location string stored in sql server table.

查看:52
本文介绍了当位置字符串存储在sql server表中时,如何从文件位置检索文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SQL Server表中存储的字符串位置(路径)在表网格中显示.

请提供示例或链接以提出解决方案.

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.

推荐答案

这取决于位置.如果使用的是客户端-服务器模型,并且文件位于某台服务器上,而不是在客户端的主机上,则需要一些服务,该服务可根据要求提供文件.因此,在服务器主机上,您需要运行FTP服务器,HTTP服务器(Web服务或网站,Web应用程序)或某些能够传递文件的自定义服务.这就是您所拥有的,可以分别使用类System.Net.FtpWebRequest或System.Net.HttpWebRequest以编程方式获取文件.请参阅:
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 [ ^ ].

如果您使用的是基于文件服务的模型,则类似的情况,但是在这种情况下,您已经有一些文件服务.因此您不需要做任何特别的事情.而且,如果您在一台计算机上都使用它,情况将是微不足道的.所以我不认为你是在问这个.

—SA
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


我的回答谢谢大家.

My answer thanks everyone.

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;
        }


这篇关于当位置字符串存储在sql server表中时,如何从文件位置检索文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆