1

I am using a FileTable in SQL Server 2012 and I want my users to download files from the FileTable. What path should I use?

public ActionResult DownloadFile(string filename)
{
    //string filename = Request.QueryString["MOVIE_FILE"];
    string path = "\\Maaz-laptop\\mssqlservermaaz\\FileDBFileStreamDirectory\\FileDirectory";
    Response.ContentType = "application/force-download;";
    Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename);
    Response.WriteFile(Server.MapPath(path) + filename);
    Response.End();
    return null;
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
MaazKhan47
  • 811
  • 1
  • 11
  • 22

2 Answers2

2

You can get access to the path by following query which can be a SQL function:

USE database_name;
DECLARE @root nvarchar(100);
DECLARE @fullpath nvarchar(1000);

SELECT @root = FileTableRootPath();
SELECT @fullpath = @root + file_stream.GetFileNamespacePath()
    FROM filetable_name
    WHERE name = N'document_name';

PRINT @fullpath;
GO

Here's the source from MSDN, Hope it'll help somebody.

Keep in mind that it's an address to windows share folder which can't make a proper address for download, you need to change it to a valid address starting with your domain name or an address that your IIS recognizes, in the given link, 2 more SQL functions has been offered, try them too, I'm still looking for a proper address for making a download link.

Muhammad Musavi
  • 2,512
  • 2
  • 22
  • 35
1

You should use the following path for example

\\SERVERNAME\FILESTREAM_WINDOWS_SHARE_NAME\FILESTREAM_TABLE_NAME\FILETABLE_DIRECTORY\

Please follow this link for information FileTable Example

Pradeep Kumar
  • 346
  • 2
  • 12
  • I just voted you up since I saw somebody voted you down by no reason, your answer might not be the exact answer but you did your best, I hate this manner that people vote down without any comment for that, I have had such experiences! – Muhammad Musavi Apr 08 '18 at 06:46