Click here to Skip to main content
15,921,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to upload or transfer XML file from my system to my webpage using windows application. My website is maintained at some other Web Hosting.
Posted

In ASP .NET MVC, View code is:

XML
<% using (Html.BeginForm("index", "home", FormMethod.Post, new { enctype = "mutipart/form-data" })) { %>
    <input type="file" name="file" />
    <input type="submit" value="Upload" />
<% } %



Controller code is:
C#
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
    if (file != null && file.ContentLength > 0 && file.ContentType == "text/xml")
    {
        var document = new XmlDocument();
        document.Load(file.InputStream);
    }
    return View();
}
 
Share this answer
 
Comments
ssyuvaraja 4-Jan-12 23:30pm    
Have any example code fully.
To upload through HTTP, you need to use WebRequest.Create[^] to create a request to your target URL, set the request content to the file, the method to POST and submit it. Server side code would then take the request and write the file content to the server file system.

Alternatively, you can use the same method with an ftp:// URL to create a FtpWebRequest[^], if you are trying to upload through FTP credentials.

In both cases, you want to include some kind of authentication, and preferably submit the request over SSL (i.e. use HTTPS for a HTTP upload or SFTP for an FTP one), so that other people can't trivially dump stuff on your server (at minimum that would permit DOS attacks, and probably much worse things like overwriting of data or parasitically using your host for their own sites).
 
Share this answer
 
Windows application:

WebClient webClient = new WebClient();
string logFileName = "file.xml";
string webAddress = null;
try
{

webAddress = @"http://localhost:1182.com/Default.aspx";


webClient.Credentials = new NetworkCredential("usrid", "psw");

WebRequest serverRequest = WebRequest.Create(webAddress);
WebResponse serverResponse;
serverResponse = serverRequest.GetResponse();
serverResponse.Close();

webClient.UploadFile(webAddress, "POST", logFileName);
webClient.Dispose();
webClient = null;

}
catch (Exception error)
{
//MessageBox.Show(error.Message);
}
 
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