-1

Below is my code, and I'm getting following error.Please help..

private const string FILEPATH = @"\\**.**.**.**\D:\BCPResult\Cust_File.txt";
string filePath = string.Empty;
filePath = Server.MapPath(FILEPATH);
string fileName = Path.GetFileName(filePath);
Response.ContentType = "text/plain";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.TransmitFile(filePath);
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.Flush();
Response.End();

Error :- \++.++.++.++\D:\BCPResult\Cust_File.txt' is not a valid virtual path.

Konamiman
  • 49,681
  • 17
  • 108
  • 138
Ashish
  • 11
  • 2
  • 2
  • 7

1 Answers1

0

Try it in windows explorer: start run: \\**.**.**.**\D:\BCPResult\Cust_File.txt

It would be \\**.**\D$\BCPResult\Cust_File.txt

But if you used that, it's a network path, not a virtual path relative to your site, so you don't need Server.MapPath() which would give you:

C:\inetpub\wwwroot\**.**\D$\BCPResult\Cust_File.txt

Where c:\inetpub\wwwroot\ is the IIS root (not your application) (it may be different) - this is because the \\ part resets outside your application root path. If you do Server.MapPath("x") it will be based on the root of your application.

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
  • Now it is saying .Access to the path '\\++.++.++.++\D$\BCPResult\Cust_File.txt' is denied..may be permission issue...how to resolve it . – Ashish Jun 16 '15 at 08:27
  • By giving permissions... D$ is a share on the remote server, so will need access through the share as well as directly on the drive. You'll be better off creating a *new* share on `D:\BCPResult` on the server: Log on the server, right click the folder, properties, sharing, advanced sharing - give read permissions to the account that your app pool uses. – freedomn-m Jun 16 '15 at 08:36
  • This might help: http://stackoverflow.com/questions/5437723/iis-apppoolidentity-and-file-system-write-access-permissions – freedomn-m Jun 16 '15 at 08:38