Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My pdf file is in server xx.xx.xx.12 and I am running my web application from local host with out publishing it.. I am using UNC path to connect to different servers. now I wanted to show pdf file located in following path.. \\xx.xx.xx.12\GeneratedPDF\031714LR9FC842DB1.pdf . on entering the path on browser, pdf file is opened but when i tried to open it via code.. i got an error:: the code is
C#
string pdfFileName = Convert.ToString(Session["pdfFileName"]);
      string fullPathOfPdfFile = string.Empty;
      fullPathOfPdfFile = @"\\xx.xx.xx.12\GeneratedPDF\" + pdfFileName;
      if (pdfFileName != null)
      {
          try
          {

              Response.ContentType = "application/pdf";
              Response.TransmitFile(fullPathOfPdfFile);
              Session.Remove("pdfFileName");
          }
          catch (Exception ex)
          {
      string message = ex.message;
          }
      }



an exception is thrown " Logon failure: unknown user name or bad password. " . i am struggling on this issue for 3 days.. can anyone help me...
Posted
Comments
VICK 17-Mar-14 3:15am    
You are on local machine and trying to access a PDF from another machine??
IF YES! Than I think it wouldn't be possible due to security issue/limitation of web browsers.

Web Application's cant acces client machin's local directory.
Codes DeCodes 17-Mar-14 4:06am    
yes you were right... i deployed it in iis and its working now.. anyway thanks for you reply,,,,
ZurdoDev 17-Mar-14 9:53am    
If it is working please post the solution so this no longer shows as unanswered.

If you are able to get the file through a web browser, then you can try WebRequest class to fetch the file from code. Here is an example of using WebRequest class:

http://msdn.microsoft.com/en-us/library/456dfw4f(v=vs.110).aspx[^]
 
Share this answer
 
You should try like in the next example:

C#
try
           {
               Response.Clear();
               Response.ClearContent();
               //
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + this.FileName);
               //
Response.Cache.SetCacheability(System.Web.HttpCacheability.Public);
               string filePath = string.Format("{0}\\{1}", Server.MapPath(this.VirtualPath), this.FileName));
               if (System.IO.File.Exists(filePath))
               {
                   Response.TransmitFile(filePath);
               }
               else
               {
                   Response.Write("File Not Found!");
               }
               //
               Response.End();
           }
           catch (Exception ex)
           {
            //...TO DO!   
           }


An in your Web.config you should have the next setting that will make accessible the "PDF folder" named "Content" to all users:

XML
<location path="Content">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900