Tôi hiện đang cố gắng ghi dữ liệu (máy khách) vào tệp xml nơi người dùng có thể lưu. Tuy nhiên, tôi muốn người dùng có thể quyết định nơi họ muốn lưu tệp xml được viết này. Có bất kỳ điều khiển hoặc mã nào tôi có thể sử dụng để cho phép người dùng lưu tệp không ?.Làm thế nào để tạo một tệp XML với ASP.NET và yêu cầu tải xuống?
Cập nhật:
là cách phù hợp để làm?
**HttpContext.Current.Response.Write(xw.ToStroing()); <<< ??????**
HttpContext.Current.Response.End();
update:
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
MemoryStream ms = new MemoryStream();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "text/xml";
HttpContext.Current.Response.AddHeader("Content-Disposition:", "attachment;filename=" + HttpUtility.UrlEncode(fileName));
using (StringWriter sw = new StringWriter())
{
using (XmlWriter xw = XmlWriter.Create(ms, settings))
{
xw.WriteStartDocument();
xw.WriteStartElement("Name");
xw.WriteStartElement("Application");
................
......................
HttpContext.Current.Response.Write(xw.ToStroing());
HttpContext.Current.Response.End();
tôi đang sử dụng và tôi đã cập nhật câu hỏi của mình, vui lòng xem và vẫn không hoạt động –
thử thay vào đó: 'using (XmlWriter xw = XmlWriter.Create (Response.OutputStream))' và sau đó không thực hiện ' HttpContext.Current.Response.Write() ' –
cũng, không chắc chắn nếu bạn nhận thấy' xw.ToStroing() 'là sai chính tả –