使用fileStream下载XML文件 [英] download an XML file Using fileStream

查看:50
本文介绍了使用fileStream下载XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,请告诉我这里的错误。我想从一个链接打开一个

XML文件。

Response.Clear()

Response.Expires = 0

Response.BufferOutput = False

Response.ContentType =" text / xml"

Response.AddHeader(" Content-Disposition",

" filename = test.XML")

Dim OStream As FileStream

Dim FileSize As Long

Dim ds作为新数据集()

OStream =新FileStream(Server.MapPath(" test.XML")),

FileMode.Open,FileAccess.Read )

ds.ReadXml(OStream)


FileSize = OStream.Length

Dim Buffer(CInt(FileSize))As Byte


OStream.Read(Buffer,0,CInt(FileSize))

OStream.Close()


Response.Write(Buffer)

Response.End()

解决方案

尝试这样的方法,其中pathfile是路径,

档案的档案名称。


Dim fStrea m作为新的System.IO.FileStream(pathfile,IO.FileMode.Open,

IO.FileAccess.Read,IO.FileShare.Read)

Dim b(ctype( fStream.Length,int32))As Byte

Response.Clear()

Response.ClearContent()

Response.ClearHeaders()

Response.ContentType =" application / unknown"
Response.AddHeader(" Content-Disposition"," attachment; filename =" +

filename)

fStream.Read(b,0,ctype(fStream.Length,int32))

Response.BinaryWrite(b)

Response.End()

fStream.Close()

fStream = Nothing

" Dorsa" <做****** @ yahoo.com>在消息中写道

news:23 ************************* @ posting.google.co m ... < blockquote class =post_quotes>请你告诉我这里的错误。我试图从链接打开一个
XML文件。

Response.Clear()
Response.Expires = 0
Response.BufferOutput = False
Response.ContentType =" text / xml"
Response.AddHeader(" Content-Disposition",
" filename = test.XML")

Dim OStream As FileStream
Dim FileSize As Long
Dim ds As New DataSet()

OStream =新FileStream(Server.MapPath(" test.XML)),
FileMode .Open,FileAccess.Read)
ds.ReadXml(OStream)

FileSize = OStream.Length
Dim Buffer(CInt(FileSize))As Byte

OStream.Close()

Response.Write(缓冲区)
Response.End()


非常感谢迈克但是她e是另一个问题。我正试图用word2003打开那个XML文件。
。我正在尝试打开的文件是一个

word文件,我将其保存为XML文件。下载

文件后,Word2003打开但无法打开文件。当我用.net编辑

下载的文件时,我在

文件的末尾看到一个额外的字符。

< / w :wordDocument> 它没有显示在这里,但它是一个矩形之后

">"

您有什么建议吗?

谢谢

Dorsa
" vMike" <弥**************** @ noYandZ.geZwaYrrenZ.com>在消息新闻中写道:< bs ********** @ ngspool-d02.news.aol.com> ...

尝试这样的方法,其中pathfile是路径,您的
文件的文件名。

Dim fStream As New System.IO.FileStream(pathfile,IO.FileMode.Open,
IO.FileAccess.Read,IO.FileShare。阅读)
Dim b(ctype(fStream.Length,int32))As Byte
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType =" application / unknown"
Response.AddHeader(" Content-Disposition"," attachment; filename =" +
filename)
fStream.Read(b ,0,ctype(fStream.Length,int32))
Response.BinaryWrite(b)
Response.End()
fStream.Close()
fStream = Nothing
Dorsa <做****** @ yahoo.com>在消息中写道
新闻:23 ************************* @ posting.google.co m ...

请你告诉我这里的错误。我试图从链接打开一个
XML文件。

Response.Clear()
Response.Expires = 0
Response.BufferOutput = False
Response.ContentType =" text / xml"
Response.AddHeader(" Content-Disposition",
" filename = test.XML")

Dim OStream As FileStream
Dim FileSize As Long
Dim ds As New DataSet()

OStream =新FileStream(Server.MapPath(" test.XML)),
FileMode .Open,FileAccess.Read)
ds.ReadXml(OStream)

FileSize = OStream.Length
Dim Buffer(CInt(FileSize))As Byte

OStream.Close()

Response.Write(缓冲区)
Response.End()



我不是回覆。我从未试图做你正在做的事情。我试了一下

,excel文件保存为xml文件,下载后工作正常。

用excel打开它。我没有单词2003和我的单词

没有xml功能(或者可能没有安装)。好像你一样

得到一个额外的字节。您可能希望重新发布您的问题或

也许有一个可能有解决方案的单词组。祝好运 。如果我在任何事情上运行
那么我会发布。


" Dorsa" <做****** @ yahoo.com>在消息中写道

news:23 ************************** @ posting.google.c om ...

非常感谢迈克但这是另一个问题。我正在尝试使用word2003打开该XML文件。我正在尝试打开的文件是一个
word文件,我将其保存为XML文件。下载
文件后,Word2003打开但无法打开文件。当我使用.net编辑
下载的文件时,我在
文档的末尾看到一个额外的字符。
< / w:wordDocument> 它没有显示在这里,但它是一个矩形
">"
你有什么建议吗?
感谢
Dorsa

" vMike" <弥**************** @ noYandZ.geZwaYrrenZ.com>在消息中写道



news:< bs ********** @ ngspool-d02.news.aol.com> ...

尝试这样的方法,其中pathfile是
文件的路径和文件名。

Dim fStream As New System.IO.FileStream(pathfile, IO.FileMode.Open,
IO.FileAccess.Read,IO.FileShare.Read)
Dim b(ctype(fStream.Length,int32))As Byte
Response.Clear()<响应.ClearContent()
Response.ClearHeaders()
Response.ContentType =" application / unknown"
Response.AddHeader(" Content-Disposition"," attachment; filename =" +
filename)
fStream.Read(b,0,ctype(fStream.Length,int32))
Response.BinaryWrite(b)
Response.End( )
fStream.Close()
fStream = Nothing
Dorsa <做****** @ yahoo.com>在消息中写道
新闻:23 ************************* @ posting.google.co m ...

请你告诉我这里的错误。我试图从链接打开一个
XML文件。

Response.Clear()
Response.Expires = 0
Response.BufferOutput = False
Response.ContentType =" text / xml"
Response.AddHeader(" Content-Disposition",
" filename = test.XML")

Dim OStream As FileStream
Dim FileSize As Long
Dim ds As New DataSet()

OStream =新FileStream(Server.MapPath(" test.XML)),
FileMode .Open,FileAccess.Read)
ds.ReadXml(OStream)

FileSize = OStream.Length
Dim Buffer(CInt(FileSize))As Byte

OStream.Close()

Response.Write(缓冲区)
Response.End()



HI, Could you please tell me the error in here. I am trying to open an
XML file from a link.
Response.Clear()
Response.Expires = 0
Response.BufferOutput = False
Response.ContentType = "text/xml"
Response.AddHeader("Content-Disposition",
"filename=test.XML")

Dim OStream As FileStream
Dim FileSize As Long
Dim ds As New DataSet()

OStream = New FileStream(Server.MapPath("test.XML"),
FileMode.Open, FileAccess.Read)
ds.ReadXml(OStream)

FileSize = OStream.Length
Dim Buffer(CInt(FileSize)) As Byte

OStream.Read(Buffer, 0, CInt(FileSize))
OStream.Close()

Response.Write(Buffer)
Response.End()

解决方案

Try something like this where pathfile is the path and file name of your
file.

Dim fStream As New System.IO.FileStream(pathfile, IO.FileMode.Open,
IO.FileAccess.Read, IO.FileShare.Read)
Dim b(ctype(fStream.Length,int32)) As Byte
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/unknown"
Response.AddHeader("Content-Disposition", "attachment;filename=" +
filename)
fStream.Read(b, 0, ctype(fStream.Length,int32))
Response.BinaryWrite(b)
Response.End()
fStream.Close()
fStream = Nothing
"Dorsa" <do******@yahoo.com> wrote in message
news:23*************************@posting.google.co m...

HI, Could you please tell me the error in here. I am trying to open an
XML file from a link.
Response.Clear()
Response.Expires = 0
Response.BufferOutput = False
Response.ContentType = "text/xml"
Response.AddHeader("Content-Disposition",
"filename=test.XML")

Dim OStream As FileStream
Dim FileSize As Long
Dim ds As New DataSet()

OStream = New FileStream(Server.MapPath("test.XML"),
FileMode.Open, FileAccess.Read)
ds.ReadXml(OStream)

FileSize = OStream.Length
Dim Buffer(CInt(FileSize)) As Byte

OStream.Read(Buffer, 0, CInt(FileSize))
OStream.Close()

Response.Write(Buffer)
Response.End()



Thanks very much mike But here is another problem. I''m trying to open
up that XML file with word2003. the file that I''m trying to open is a
word file which I had saved it as an XML file. After I download the
file, Word2003 opens up but it can''t open the file. when I edit the
downloaded file with .net, I see an extra character at the end of the
document.
</w:wordDocument> "it doesn''t show here but it''s a rectangle" after
">"
Do you have any suggestion?
thanks
Dorsa
"vMike" <Mi****************@noYandZ.geZwaYrrenZ.com> wrote in message news:<bs**********@ngspool-d02.news.aol.com>...

Try something like this where pathfile is the path and file name of your
file.

Dim fStream As New System.IO.FileStream(pathfile, IO.FileMode.Open,
IO.FileAccess.Read, IO.FileShare.Read)
Dim b(ctype(fStream.Length,int32)) As Byte
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/unknown"
Response.AddHeader("Content-Disposition", "attachment;filename=" +
filename)
fStream.Read(b, 0, ctype(fStream.Length,int32))
Response.BinaryWrite(b)
Response.End()
fStream.Close()
fStream = Nothing
"Dorsa" <do******@yahoo.com> wrote in message
news:23*************************@posting.google.co m...

HI, Could you please tell me the error in here. I am trying to open an
XML file from a link.
Response.Clear()
Response.Expires = 0
Response.BufferOutput = False
Response.ContentType = "text/xml"
Response.AddHeader("Content-Disposition",
"filename=test.XML")

Dim OStream As FileStream
Dim FileSize As Long
Dim ds As New DataSet()

OStream = New FileStream(Server.MapPath("test.XML"),
FileMode.Open, FileAccess.Read)
ds.ReadXml(OStream)

FileSize = OStream.Length
Dim Buffer(CInt(FileSize)) As Byte

OStream.Read(Buffer, 0, CInt(FileSize))
OStream.Close()

Response.Write(Buffer)
Response.End()



Well I am not sure. I have never tried to do what you are doing. I tried it
with an excel file saved as a xml file and it worked fine after downloading
it an openning it with excel. I don''t have word 2003 and my version of word
doesn''t have an xml feature (or maybe it isn''t installed). Seems like you
are getting an extra byte. You might want to repost with your problem or
maybe there is a word group that might have a solution. Good luck . If I
run accross anything then I will post.

"Dorsa" <do******@yahoo.com> wrote in message
news:23**************************@posting.google.c om...

Thanks very much mike But here is another problem. I''m trying to open
up that XML file with word2003. the file that I''m trying to open is a
word file which I had saved it as an XML file. After I download the
file, Word2003 opens up but it can''t open the file. when I edit the
downloaded file with .net, I see an extra character at the end of the
document.
</w:wordDocument> "it doesn''t show here but it''s a rectangle" after
">"
Do you have any suggestion?
thanks
Dorsa
"vMike" <Mi****************@noYandZ.geZwaYrrenZ.com> wrote in message


news:<bs**********@ngspool-d02.news.aol.com>...

Try something like this where pathfile is the path and file name of your
file.

Dim fStream As New System.IO.FileStream(pathfile, IO.FileMode.Open,
IO.FileAccess.Read, IO.FileShare.Read)
Dim b(ctype(fStream.Length,int32)) As Byte
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/unknown"
Response.AddHeader("Content-Disposition", "attachment;filename=" +
filename)
fStream.Read(b, 0, ctype(fStream.Length,int32))
Response.BinaryWrite(b)
Response.End()
fStream.Close()
fStream = Nothing
"Dorsa" <do******@yahoo.com> wrote in message
news:23*************************@posting.google.co m...

HI, Could you please tell me the error in here. I am trying to open an
XML file from a link.
Response.Clear()
Response.Expires = 0
Response.BufferOutput = False
Response.ContentType = "text/xml"
Response.AddHeader("Content-Disposition",
"filename=test.XML")

Dim OStream As FileStream
Dim FileSize As Long
Dim ds As New DataSet()

OStream = New FileStream(Server.MapPath("test.XML"),
FileMode.Open, FileAccess.Read)
ds.ReadXml(OStream)

FileSize = OStream.Length
Dim Buffer(CInt(FileSize)) As Byte

OStream.Read(Buffer, 0, CInt(FileSize))
OStream.Close()

Response.Write(Buffer)
Response.End()



这篇关于使用fileStream下载XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆