根据条件

时间:2016-07-16 16:49:24

标签: c# asp.net sql-server filesystems document-management

我正在使用C#在ASP.NET中使用文档管理系统。我将所有文件夹和文件存储在Windows服务器上,并将文件夹和文件信息保存在SQL数据库中。每次,我在服务器上创建一个文件夹或文件,我从数据库中添加唯一ID的名称。示例:contact~432cace7-a39c-4db5-a38f-9efe5d289bbf.pdf

现在我们有不同的用户可以访问相同的文件夹,并且需要根据他们的访问权限进行删除和下载。

示例:我有2个用户,user-1和user-2。我有一个包含2个文件的文件夹-1。 file-1由user-1上传,file-2由user-2上传。现在,当用户1在浏览器页面中查看文件时,我会根据数据库查询显示文件夹-1并在该文件-1中。但是如果用户1选择文件夹-1进行下载,它将转到Windows服务器并下载文件1和文件2,因为它们在服务器上的同一文件夹中。删除的情况也是如此。

我该如何处理这种情况?

基本上,使用关系数据库在SQL中处理很容易,但我在想如何在Windows服务器上有效地完成这项工作?

我的想法:调用一个DB存储过程,它返回id列表,并根据它生成下载zip或删除。但是,由于可以嵌套文件夹和文件,这在性能方面效率如何?

1 个答案:

答案 0 :(得分:-1)

请按照以下代码处理:

在Js文件中:

var file_name = response.value[0]["name"];
var downloadurl = response.value[0]"@microsoft.graph.downloadUrl"];

// --------------------------------------------- -------------------------- //

function HandleIT(downloadurl,file_name) {
    PageMethods.ProcessIT(downloadurl,file_name, onSucess, onError);
    function onSucess(result) {
        alert(result);       
    }
    function onError(result) {
        alert('Something wrong.');
    }
}

在我们的代码中,Webmethod:

[WebMethod]
        public static string ProcessIT(string downloadURL, string file_name)
        {            
            // Create a new WebClient instance.
            WebClient myWebClient = new WebClient();
            string  path = @"c:\";
            string path_n_name = path + file_name; 
            // Download the Web resource and save it into the current filesystem folder.
            myWebClient.DownloadFile(downloadURL, path_n_name);
            return "SUCCESS";
        }

这是我删除文件的方式

if(fileName != null || fileName != string.empty)
    {
       if((System.IO.File.Exists(fileName))
           System.IO.File.Delete(fileName);

     }

希望它适合你......!

相关问题