Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to send xml file or data to a server and save it locally?

Status
Not open for further replies.

Awsok

Programmer
Apr 11, 2005
6
DK
Hi folk...
and thanks for reading this

I have an Xml file that I need to send from my PC to a server we have on the other side.

I know that its possible to use HttpWebRequest to post the data of my file to another ASP.Net App. working on the server side?

But what should I do to make the server side app. listen and accept my sent data and save them locally[ponder]?

Any idea how to do that easitly?

Thanks
 
Hi again...
I have an Xml file that I need to send or upload from my Windows Application, to a server we have on the other side using asp.net application running on the server!


I know that its possible to use HttpWebRequest to post the data of my file to another ASP.Net App. working on the server side, so I made this code:

string result = "";
// postData is an Xml Data from the file 1.xml
string postData = GetDataFromXmlFile(“1.xml”);
string url =
HttpWebRequest objRequest2 = null;
HttpWebResponse objResponse2 = null;
try
{
objRequest2 = (HttpWebRequest) System.Net.HttpWebRequest.Create(url);
objRequest2.KeepAlive = false;
objRequest2.Method = "POST";
objRequest2.AllowAutoRedirect = true;
objRequest2.ContentLength = postData.Length;
objRequest2.ContentType = "text/xml";
objRequest2.Timeout = 100000;
objRequest2.CookieContainer = new CookieContainer();
objRequest2.AllowWriteStreamBuffering = true;
StreamWriter myWriter = new StreamWriter(objRequest2.GetRequestStream());
myWriter.Write(postData);
myWriter.Close();

objResponse2 = (HttpWebResponse)objRequest2.GetResponse();
using (StreamReader sr = new StreamReader(objResponse2.GetResponseStream(), Encoding.GetEncoding("windows-1252")) )
{
result = sr.ReadToEnd();
sr.Close();
}
}
catch(Exception ex)
{
Debug.WriteLine("get and exception"+ ex.ToString());
}

But what should I do or write to make my server side asp.net app. listen and accept my sent data and save them locally?

I tried the following code on the page load of my asp.net app but don’t work, since the postData is not displayed on the my asp.net page!!

private void Page_Load(object sender, System.EventArgs e)
{
StreamReader reader = new StreamReader(Page.Request.InputStream);
string xmlData = reader.ReadToEnd();
lblOutput.Text += xmlData;
}

Any idea how to do that easily?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top