Click here to Skip to main content
15,907,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to write some output into .csv file which is at my server.
I use following code but still there is no output in file.
means nothing is written. my code is here.

C#
void WriteInRegister(DataRow userdata)
        {
            HttpWebRequest reqHTTP;
            StringBuilder result = new StringBuilder();
            try
            {
                reqHTTP = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://10.10.10.10/config/RequestPlacer.csv"));
                reqHTTP.Credentials = new NetworkCredential("usename", "password");

                if (reqHTTP != null)
                {
                    reqHTTP.ContentType = "application/octet-stream";
                    reqHTTP.Method = WebRequestMethods.File.UploadFile;
                }
                string postdata = (userdata[0].ToString() + ",MacId," + DateTime.Now.ToShortDateString()).ToString();
                byte[] text = Encoding.UTF8.GetBytes(postdata);

                reqHTTP.ContentLength = text.Length;

              /* WebClient wcClient = new WebClient();
                wcClient.Credentials = new NetworkCredential("usename", "password");
                wcClient.UseDefaultCredentials = true;*/
                //wcClient.OpenWrite(new Uri("http://10.10.10.10/config/RequestPlacer.csv"), postdata);


                //  string path = System.Web.HttpContext.Current.Server.MapPath("http://10.10.10.10/config/RequestPlacer.csv");
                   reqHTTP.AllowWriteStreamBuffering = true;
                   Stream writer = reqHTTP.GetRequestStream();
                  /* wcClient.Headers.Add("Content-Type", "application/csv");
                   wcClient.UploadString(new Uri("http://10.10.10.10/config/RequestPlacer.csv"), "POST", postdata);*/


                StreamWriter streamwriter = new StreamWriter(writer);
                streamwriter.WriteLine(postdata);
                streamwriter.Close();
            }
            catch (Exception exe)
            {
                MessageBox.Show(exe.Message);
            }
        }


Exception is("The request was aborted: The request was canceled.")
Posted
Comments
Kornfeld Eliyahu Peter 5-Oct-14 2:13am    
You are writing on the stream of the HTTP request! What have you expected?!
BharatPrajapati212 6-Oct-14 5:02am    
nothing will happen
Herman<T>.Instance 6-Oct-14 6:24am    
What if the remote server has now webserver?
What if the remote serer firewall blocks write requests on port 80?
What if the IIS user has no rigths to write on the remote folder?
Can you answer these questions?
BharatPrajapati212 6-Oct-14 8:38am    
that is interesting @digimanus
BharatPrajapati212 9-Nov-14 23:10pm    
Thanks @OriginalBot

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