i created a xml file using vs2005.This xml file is saving to c:/.
Now i want to know how can clients download this file to thre own PC.
I wrote the code like as follows.But i am getting error like as follows
he process cannot access the file "path\filename.xml" because it is being used by another process.
Dim myXmlSettings As New XmlWriterSettings
myXmlSettings.Indent = True
Dim myXmlWriter As XmlWriter = XmlWriter.Create(Server.MapPath(user4mapping & ".xml"), myXmlSettings)
Download("~/" & user4mapping & ".xml")
Public Sub Download(ByVal path As String)
Dim fileInfo As New FileInfo(Server.MapPath(path))
If fileInfo.Exists Then
Dim fullname As String = fileInfo.FullName
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", fileInfo.Name))
Response.WriteFile(fullname)
Response.End()
End If
End Sub
same download function is working for downloading the pdf file.
Not possible to download the file while writing mode becuase it will used by another process , so you need do wait for untill the file write operation finished. after that you have to download the file.
not possible to perform both read/write operation it shows error message like
the process cannot access the file "path\filename.xml" because it is being used by another process.
You have to save your .xml file in your main projects some folder. suppose you have download that .xml file just you have refer the locations from main Projects. don't save the file different location.
ok..but i am trying to download after finishing the write operation na???see the code below..
Dim myXmlWriter As XmlWriter = XmlWriter.Create(Server.MapPath(user4mapping & ".xml"), myXmlSettings)
Download("~/" & user4mapping & ".xml")
If this is wrong ,can u tell me where i can put this download function???
Well,suppose you've created an xml file quickly and fine……Let's say——
Public Sub Download(ByVal path As String)
Dim fileInfo As New FileInfo(Server.MapPath(path))
If fileInfo.Exists Then
Dim fullname As String = fileInfo.FullName
Response.Clear()
Response.ContentType = "text/xml"
Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", fileInfo.Name))
Response.WriteFile(fullname)
Response.End()
End If
End Sub
Also you can see my demo here:
Namespace WebCSharp
Public Partial Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
Dim s As String = "<root>a</root>"
'You should use:File.ReadAllText("xxx.xml");
Response.Clear()
Response.ContentType = "text/xml"
Response.AddHeader("Content-Disposition", [String].Format("attachment; filename={0}", "test"))
Response.Write(s)
Response.[End]()
End If
End Sub
End Class
End Namespace
jula
Member
172 Points
430 Posts
download xml file
Feb 07, 2012 01:00 AM|LINK
hi all,
i created a xml file using vs2005.This xml file is saving to c:/.
Now i want to know how can clients download this file to thre own PC.
I wrote the code like as follows.But i am getting error like as follows
Dim myXmlSettings As New XmlWriterSettings myXmlSettings.Indent = True Dim myXmlWriter As XmlWriter = XmlWriter.Create(Server.MapPath(user4mapping & ".xml"), myXmlSettings) Download("~/" & user4mapping & ".xml")
Public Sub Download(ByVal path As String) Dim fileInfo As New FileInfo(Server.MapPath(path)) If fileInfo.Exists Then Dim fullname As String = fileInfo.FullName Response.Clear() Response.ContentType = "application/octet-stream" Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", fileInfo.Name)) Response.WriteFile(fullname) Response.End() End If End Subsame download function is working for downloading the pdf file.
Please help me...
dinakaran
Member
625 Points
216 Posts
Re: download xml file
Feb 07, 2012 02:37 AM|LINK
Helo Jula,
Not possible to download the file while writing mode becuase it will used by another process , so you need do wait for untill the file write operation finished. after that you have to download the file.
not possible to perform both read/write operation it shows error message like
the process cannot access the file "path\filename.xml" because it is being used by another process.
You have to save your .xml file in your main projects some folder. suppose you have download that .xml file just you have refer the locations from main Projects. don't save the file different location.
jula
Member
172 Points
430 Posts
Re: download xml file
Feb 08, 2012 11:24 AM|LINK
ok..but i am trying to download after finishing the write operation na???see the code below..
Dim myXmlWriter As XmlWriter = XmlWriter.Create(Server.MapPath(user4mapping & ".xml"), myXmlSettings) Download("~/" & user4mapping & ".xml") If this is wrong ,can u tell me where i can put this download function???Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: download xml file
Feb 09, 2012 12:30 AM|LINK
Well,suppose you've created an xml file quickly and fine……Let's say——
Public Sub Download(ByVal path As String) Dim fileInfo As New FileInfo(Server.MapPath(path)) If fileInfo.Exists Then Dim fullname As String = fileInfo.FullName Response.Clear() Response.ContentType = "text/xml" Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", fileInfo.Name)) Response.WriteFile(fullname) Response.End() End If End SubAlso you can see my demo here:Namespace WebCSharp Public Partial Class WebForm1 Inherits System.Web.UI.Page Protected Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then Dim s As String = "<root>a</root>" 'You should use:File.ReadAllText("xxx.xml"); Response.Clear() Response.ContentType = "text/xml" Response.AddHeader("Content-Disposition", [String].Format("attachment; filename={0}", "test")) Response.Write(s) Response.[End]() End If End Sub End Class End Namespace