0

I'm trying to create a directory on the server for saving files as links, when I create a directory it gives access denied to the file path.

This is how I do it

public static string CreateFile(string FilePath)
{
        string Path = "";
        string RootPath = System.Web.HttpContext.Current.Server.MapPath("");
        //RootPath = RootPath.Substring(0, RootPath.Length - cropsize);
        System.IO.DirectoryInfo DirInfo = new System.IO.DirectoryInfo(RootPath + FilePath);
        System.Security.AccessControl.DirectorySecurity DirPermission = new System.Security.AccessControl.DirectorySecurity();
        System.Security.AccessControl.FileSystemAccessRule FRule = new System.Security.AccessControl.FileSystemAccessRule
            ("Everyone", System.Security.AccessControl.FileSystemRights.ReadAndExecute, System.Security.AccessControl.AccessControlType.Allow);
        DirPermission.AddAccessRule(FRule);

        if (DirInfo.Exists == false)
        {
            System.IO.Directory.CreateDirectory(RootPath + FilePath);
        }

        Path = RootPath + FilePath;

        return Path;
    }

It's a Web API, not a website.

I'm uploading the files from a mobile, I managed the reading part.

The Server.MapPath("") is returning D:\\home...\\api

It's located on an external server

I tried this code running the service locally and it worked, but on external server it gives the error above.

Also, is there an other way to save the files as links?

About the problem:

I'm uploading the file from a mobile device and reading the file from the service as byte[], and I don't want to save the bytes directly to the database, I only want the Url of the file.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ibraheem Al-Saady
  • 854
  • 3
  • 14
  • 30

0 Answers0