Click here to Skip to main content
15,905,913 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a database server in one computer (say xx.xx.xx.12) and web application installed in another computer (say xx.xx.xx.243).. in web application, when user fills records and clicks on submit, records are stored in database.. here, a pdf file is generated(i.e. in xx.xx.xx.12). Now, i have to dispaly this pdf file when user runs web application i.e. xx.xx.xx.243. what my logic is to download the file from xx.xx.xx.12 to xx.xx.xx.243. i had this code ..

Uri serverUri = new Uri("ftp://xx.xx.xx.12/C:/test.txt");
Boolean status = DisplayFileFromServer(serverUri);
C#
private static Boolean DisplayFileFromServer(Uri serverUri)
   {
       if (serverUri.Scheme != Uri.UriSchemeFtp)
     {
         return false;
     }
       WebClient request = new WebClient();
       request.Credentials = new NetworkCredential("krishab.shakya","Welcome@2014");
       try
       {
           byte[] newFileData = request.DownloadData(serverUri.ToString());
           string filestring = System.Text.Encoding.UTF8.GetString(newFileData);


       }
       catch (WebException ex)
       {
           string status = ex.Status.ToString();
           string res =  ex.Response.ToString();

           string error = ex.Message;
       }
       return true;
   }


here, an error object reference not set to instance of an object is thrown as compiler enters line byte[] newFileData = request.DownloadData(serverUri.ToString()); . it might be because program is not taking "ftp://xx.xx.xx.12/C:/test.txt" .. I dont know why is it not taking this address.. is this that ftp configuration is required.. OR Is there another simple logic to show pdf file stored in one server to display in browser of another server !!
Posted

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