User-1162043308 posted
I am uploading the xml file by using below code.my question is that existing file need not be updated just appened the added data.for that wrote the below code.
[WebInvoke(UriTemplate = "XmlFile?id={id}", Method = "POST")]
public bool XmlFile(string id, Stream createText)
{
string filenamewithpath = System.Web.HttpContext.Current.Server.MapPath(@"~/xmlfiles/" + id + ".xml");
if (File.Exists(filenamewithpath))
{
FileStream fl = new FileStream(filenamewithpath, FileMode.Append);
StreamWriter w = File.AppendText(filenamewithpath);
w.WriteLine( Util.ReadFully(createText));
}else{
System.IO.File.WriteAllBytes(filenamewithpath, Util.ReadFully(createText));
}
Util.cs:
public static class Util
{
public static byte[] ReadFully(Stream stream)
{
byte[] buffer = new byte[32768];
using (MemoryStream ms = new MemoryStream())
{
while (true)
{
int read = stream.Read(buffer, 0, buffer.Length);
if (read <= 0)
return ms.ToArray();
ms.Write(buffer, 0, read);
}
}
}
}
I am not able to appened the data to existing file?please tell me how to add the stream data to existing file?