0

I am working on Document Management System in ASP.NET using C#. I store all folders and files on a windows server and save folder and file info in SQL database as well. Everytime, I create a folder or file on server, I append the name with unique id from database. Example: contact~432cace7-a39c-4db5-a38f-9efe5d289bbf.pdf

Now we have different users who have access to same folders and need a way to delete and download based on their access.

Example: I have 2 users, user-1 and user-2. I have a folder-1 which contains 2 files. file-1 is uploaded by user-1 and file-2 by user-2. Now when user-1 views the file in browser page, I show folder-1 and within that file-1 based on database query. But if user one selects folder-1 for download, it will go to the windows server and download both file-1 and file-2 as physically they are within same folder on server. Same is the case with delete too.

How can I handle this scenario?

Basically, handling in SQL is much easy with relational database but I am thinking how can this be done on windows server efficiently?

My Idea: Call a DB stored proc that returns list of ids and based on that generate the download zip or delete. But since there can be nesting of folder and files, how efficient will this be in performance?

Naupad Doshi
  • 496
  • 2
  • 5
  • 19
  • Can your user navigate directly to the file or folder using the browsers URL ? Can they download someone elses file just by guessing the file name based on the URL format used to download their own files ? – PhillipH Jul 16 '16 at 18:39
  • Users can guess the file name but they cannot guess the unique guid of the file associated with that name. Like if u notice my example above, file and folder names will be in format: name~guid – Naupad Doshi Jul 16 '16 at 18:43

1 Answers1

-1

Follow the code below and process :

In Js File :

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.');
    }
}

In Code Behind us the 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";
        }

This is how I delete files

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

     }

Hope it works for you...!

Sanjeev Sangral
  • 1,385
  • 2
  • 25
  • 37