Problem in uploading file with HttpWebRequest
-
Hi all, I am getting problem in uploading file with ASP.NET (C#). I have set almost all property of HttpWebRequest instance. I have too set properties in my Virtual directory. I am getting error as "Cannot connect to the configuration database". I dont know what is configuration database in these case. My application takes 10 second when it execute the below code: HttpWebResponse httpResponse =httpWebResponse)httpRequest.GetResponse(); I have used Stream to write uploaded file content. It seems to be working fine. Even I am getting my Stream object by GetRequestStream(). ======================================================================== here is my code. string URI = "http://" + txtServerIP.Text + "/" + "VDir" + "/" + fUpload.FileName; HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(new Uri(URI)); FileInfo fileInfo = new FileInfo(fUpload.PostedFile.FileName); httpRequest.Method = WebRequestMethods.Http.Put; httpRequest.AllowWriteStreamBuffering = true; httpRequest.Credentials = new NetworkCredential(txtUserName.Text, txtPassword.Text); httpRequest.ContentLength = fileInfo.Length; httpRequest.ContentType ="text/html"; FileStream fs = new FileStream(fUpload.PostedFile.FileName,FileMode.Open); Stream stream = httpRequest.GetRequestStream(); contentLength = fs.Read(buff, 0, buffLen); while (contentLength != 0) { stream.Write(buff, 0, contentLength); contentLength = fs.Read(buff, 0, buffLen); } stream.Close(); fs.Close(); //Here it takes 10 seconds.:mad: HttpWebResponse response = (HttpWebResponse)httpRequest.GetResponse(); Could you pls help me. Thanks,
Regards Chintan HCL Technologies...India (Carefully) listen->(Deeply)Think->(Clearly)Understand->(Patiently) reply...
-
Hi all, I am getting problem in uploading file with ASP.NET (C#). I have set almost all property of HttpWebRequest instance. I have too set properties in my Virtual directory. I am getting error as "Cannot connect to the configuration database". I dont know what is configuration database in these case. My application takes 10 second when it execute the below code: HttpWebResponse httpResponse =httpWebResponse)httpRequest.GetResponse(); I have used Stream to write uploaded file content. It seems to be working fine. Even I am getting my Stream object by GetRequestStream(). ======================================================================== here is my code. string URI = "http://" + txtServerIP.Text + "/" + "VDir" + "/" + fUpload.FileName; HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(new Uri(URI)); FileInfo fileInfo = new FileInfo(fUpload.PostedFile.FileName); httpRequest.Method = WebRequestMethods.Http.Put; httpRequest.AllowWriteStreamBuffering = true; httpRequest.Credentials = new NetworkCredential(txtUserName.Text, txtPassword.Text); httpRequest.ContentLength = fileInfo.Length; httpRequest.ContentType ="text/html"; FileStream fs = new FileStream(fUpload.PostedFile.FileName,FileMode.Open); Stream stream = httpRequest.GetRequestStream(); contentLength = fs.Read(buff, 0, buffLen); while (contentLength != 0) { stream.Write(buff, 0, contentLength); contentLength = fs.Read(buff, 0, buffLen); } stream.Close(); fs.Close(); //Here it takes 10 seconds.:mad: HttpWebResponse response = (HttpWebResponse)httpRequest.GetResponse(); Could you pls help me. Thanks,
Regards Chintan HCL Technologies...India (Carefully) listen->(Deeply)Think->(Clearly)Understand->(Patiently) reply...
I doubt the problem is with your code. The error returned is from the server and is probably because your server has SharePoint installed. Search google for the error message and there are a ton of results which talk about this specific error. http://www.google.com/search?hl=en&rls=com.microsoft%3Aen-US&q=Cannot+connect+to+the+configuration+database[^] If none of these seem to help solve your problem then you'll need to post some more information about the configuration of the server you are trying to communicate with.
Mark's blog: developMENTALmadness.blogspot.com