Hi nanna_rammohan_vsp@hotmail.com, ,
nanna_rammohan_vsp@hotmail.com:I want to upload the xml file and retive the xml file through web services...
So you need to create one Web Service first. Create one web method :
[WebMethod]
public string UploadFile(byte[] fs, string FileName)
{
try
{
MemoryStream m = new MemoryStream(fs);
FileStream f = new FileStream("d:\\" + FileName, FileMode.Create);
m.WriteTo(f);
m.Close();
f.Close();
f = null;
m = null;
return "ok";
}
catch (Exception ex)
{
return ex.Message;
}
}
Create one page :
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="up" />
</div>
</form> protected void Button1_Click(object sender, EventArgs e)
{
if(FileUpload1.PostedFile != null)
{
System.Web.HttpFileCollection oFiles;
oFiles = System.Web.HttpContext.Current.Request.Files;
if(oFiles.Count < 1)
{
Response.Write ("please select file");
Response.End();
}
string FilePath = oFiles[0].FileName;
if(FilePath == "" || FilePath == null)
{
Response.Write("please select file");
Response.End();
}
string FileName = FilePath.Substring(FilePath.LastIndexOf("\\")+1);
try
{
byte[] b = new byte[oFiles[0].ContentLength];
System.IO.Stream fs;
localhost.Service1 o;
o = new localhost.Service1();
fs = (System.IO.Stream)oFiles[0].InputStream;
fs.Read(b, 0, oFiles[0].ContentLength);
Response.Write(o.UploadFile(b, FileName));
fs.Close();
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
else
{
Response.Write("please select file");
}
}