473,753 Members | 6,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

download an XML file Using fileStream

HI, Could you please tell me the error in here. I am trying to open an
XML file from a link.
Response.Clear( )
Response.Expire s = 0
Response.Buffer Output = False
Response.Conten tType = "text/xml"
Response.AddHea der("Content-Disposition",
"filename=test. XML")

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

OStream = New FileStream(Serv er.MapPath("tes t.XML"),
FileMode.Open, FileAccess.Read )
ds.ReadXml(OStr eam)

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

OStream.Read(Bu ffer, 0, CInt(FileSize))
OStream.Close()

Response.Write( Buffer)
Response.End()
Nov 18 '05 #1
11 4045
Try something like this where pathfile is the path and file name of your
file.

Dim fStream As New System.IO.FileS tream(pathfile, IO.FileMode.Ope n,
IO.FileAccess.R ead, IO.FileShare.Re ad)
Dim b(ctype(fStream .Length,int32)) As Byte
Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/unknown"
Response.AddHea der("Content-Disposition", "attachment;fil ename=" +
filename)
fStream.Read(b, 0, ctype(fStream.L ength,int32))
Response.Binary Write(b)
Response.End()
fStream.Close()
fStream = Nothing
"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** **@posting.goog le.com...
HI, Could you please tell me the error in here. I am trying to open an
XML file from a link.
Response.Clear( )
Response.Expire s = 0
Response.Buffer Output = False
Response.Conten tType = "text/xml"
Response.AddHea der("Content-Disposition",
"filename=test. XML")

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

OStream = New FileStream(Serv er.MapPath("tes t.XML"),
FileMode.Open, FileAccess.Read )
ds.ReadXml(OStr eam)

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

OStream.Read(Bu ffer, 0, CInt(FileSize))
OStream.Close()

Response.Write( Buffer)
Response.End()

Nov 18 '05 #2
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.ge ZwaYrrenZ.com> wrote in message news:<bs******* ***@ngspool-d02.news.aol.co m>...
Try something like this where pathfile is the path and file name of your
file.

Dim fStream As New System.IO.FileS tream(pathfile, IO.FileMode.Ope n,
IO.FileAccess.R ead, IO.FileShare.Re ad)
Dim b(ctype(fStream .Length,int32)) As Byte
Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/unknown"
Response.AddHea der("Content-Disposition", "attachment;fil ename=" +
filename)
fStream.Read(b, 0, ctype(fStream.L ength,int32))
Response.Binary Write(b)
Response.End()
fStream.Close()
fStream = Nothing
"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** **@posting.goog le.com...
HI, Could you please tell me the error in here. I am trying to open an
XML file from a link.
Response.Clear( )
Response.Expire s = 0
Response.Buffer Output = False
Response.Conten tType = "text/xml"
Response.AddHea der("Content-Disposition",
"filename=test. XML")

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

OStream = New FileStream(Serv er.MapPath("tes t.XML"),
FileMode.Open, FileAccess.Read )
ds.ReadXml(OStr eam)

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

OStream.Read(Bu ffer, 0, CInt(FileSize))
OStream.Close()

Response.Write( Buffer)
Response.End()

Nov 18 '05 #3
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.goo gle.com...
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.ge ZwaYrrenZ.com> wrote in message

news:<bs******* ***@ngspool-d02.news.aol.co m>...
Try something like this where pathfile is the path and file name of your
file.

Dim fStream As New System.IO.FileS tream(pathfile, IO.FileMode.Ope n,
IO.FileAccess.R ead, IO.FileShare.Re ad)
Dim b(ctype(fStream .Length,int32)) As Byte
Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/unknown"
Response.AddHea der("Content-Disposition", "attachment;fil ename=" +
filename)
fStream.Read(b, 0, ctype(fStream.L ength,int32))
Response.Binary Write(b)
Response.End()
fStream.Close()
fStream = Nothing
"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** **@posting.goog le.com...
HI, Could you please tell me the error in here. I am trying to open an
XML file from a link.
Response.Clear( )
Response.Expire s = 0
Response.Buffer Output = False
Response.Conten tType = "text/xml"
Response.AddHea der("Content-Disposition",
"filename=test. XML")

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

OStream = New FileStream(Serv er.MapPath("tes t.XML"),
FileMode.Open, FileAccess.Read )
ds.ReadXml(OStr eam)

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

OStream.Read(Bu ffer, 0, CInt(FileSize))
OStream.Close()

Response.Write( Buffer)
Response.End()

Nov 18 '05 #4
One other probably obvious thing is have you tried reopenning it with
Word2003 before it is downloaded to see that Word is creating a valid xml
file. I read a few threads about it and it fairly new and there have been
some problems with Word documents which contain grahics and other features.

"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** ***@posting.goo gle.com...
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.ge ZwaYrrenZ.com> wrote in message

news:<bs******* ***@ngspool-d02.news.aol.co m>...
Try something like this where pathfile is the path and file name of your
file.

Dim fStream As New System.IO.FileS tream(pathfile, IO.FileMode.Ope n,
IO.FileAccess.R ead, IO.FileShare.Re ad)
Dim b(ctype(fStream .Length,int32)) As Byte
Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/unknown"
Response.AddHea der("Content-Disposition", "attachment;fil ename=" +
filename)
fStream.Read(b, 0, ctype(fStream.L ength,int32))
Response.Binary Write(b)
Response.End()
fStream.Close()
fStream = Nothing
"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** **@posting.goog le.com...
HI, Could you please tell me the error in here. I am trying to open an
XML file from a link.
Response.Clear( )
Response.Expire s = 0
Response.Buffer Output = False
Response.Conten tType = "text/xml"
Response.AddHea der("Content-Disposition",
"filename=test. XML")

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

OStream = New FileStream(Serv er.MapPath("tes t.XML"),
FileMode.Open, FileAccess.Read )
ds.ReadXml(OStr eam)

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

OStream.Read(Bu ffer, 0, CInt(FileSize))
OStream.Close()

Response.Write( Buffer)
Response.End()

Nov 18 '05 #5
yes, there is an extra character at the end. I couldn't find the
reason and I also tried with other Response.Conten tType but seems that
it dosen't care what for that value. Do you any idea how I can delete
that character byte at the end after ">" ?
Also, Is there another way for getting my XML file into word? Can you
tell me about why you used binary for output?
Thanks
Dorsa
"vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.com> wrote in message news:<bs******* ***@ngspool-d02.news.aol.co m>...
One other probably obvious thing is have you tried reopenning it with
Word2003 before it is downloaded to see that Word is creating a valid xml
file. I read a few threads about it and it fairly new and there have been
some problems with Word documents which contain grahics and other features.

"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** ***@posting.goo gle.com...
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.ge ZwaYrrenZ.com> wrote in message

news:<bs******* ***@ngspool-d02.news.aol.co m>...
Try something like this where pathfile is the path and file name of your
file.

Dim fStream As New System.IO.FileS tream(pathfile, IO.FileMode.Ope n,
IO.FileAccess.R ead, IO.FileShare.Re ad)
Dim b(ctype(fStream .Length,int32)) As Byte
Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/unknown"
Response.AddHea der("Content-Disposition", "attachment;fil ename=" +
filename)
fStream.Read(b, 0, ctype(fStream.L ength,int32))
Response.Binary Write(b)
Response.End()
fStream.Close()
fStream = Nothing
"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** **@posting.goog le.com...
> HI, Could you please tell me the error in here. I am trying to open an
> XML file from a link.
>
>
> Response.Clear( )
> Response.Expire s = 0
> Response.Buffer Output = False
> Response.Conten tType = "text/xml"
> Response.AddHea der("Content-Disposition",
> "filename=test. XML")
>
> Dim OStream As FileStream
> Dim FileSize As Long
> Dim ds As New DataSet()
>
> OStream = New FileStream(Serv er.MapPath("tes t.XML"),
> FileMode.Open, FileAccess.Read )
> ds.ReadXml(OStr eam)
>
> FileSize = OStream.Length
> Dim Buffer(CInt(Fil eSize)) As Byte
>
> OStream.Read(Bu ffer, 0, CInt(FileSize))
> OStream.Close()
>
> Response.Write( Buffer)
> Response.End()

Nov 18 '05 #6
Have you tried just a straight forward file write such as. You might also
want to mess with the ContentType

Dim fi as System.IO.FileI nfo = new System.IO.FileI nfo(youpathandf ilename)

Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/unknown"
Response.AddHea der("Content-Disposition", "attachment;fil ename=" +
filename)
Response.WriteF ile(fi.fullname )
Response.End()

fi = Nothing

"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** ***@posting.goo gle.com...
yes, there is an extra character at the end. I couldn't find the
reason and I also tried with other Response.Conten tType but seems that
it dosen't care what for that value. Do you any idea how I can delete
that character byte at the end after ">" ?
Also, Is there another way for getting my XML file into word? Can you
tell me about why you used binary for output?
Thanks
Dorsa
"vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.com> wrote in message

news:<bs******* ***@ngspool-d02.news.aol.co m>...
One other probably obvious thing is have you tried reopenning it with
Word2003 before it is downloaded to see that Word is creating a valid xml file. I read a few threads about it and it fairly new and there have been some problems with Word documents which contain grahics and other features.
"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** ***@posting.goo gle.com...
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.ge ZwaYrrenZ.com> wrote in message

news:<bs******* ***@ngspool-d02.news.aol.co m>...
> Try something like this where pathfile is the path and file name of your > file.
>
> Dim fStream As New System.IO.FileS tream(pathfile, IO.FileMode.Ope n,
> IO.FileAccess.R ead, IO.FileShare.Re ad)
> Dim b(ctype(fStream .Length,int32)) As Byte
> Response.Clear( )
> Response.ClearC ontent()
> Response.ClearH eaders()
> Response.Conten tType = "applicatio n/unknown"
> Response.AddHea der("Content-Disposition", "attachment;fil ename=" + > filename)
> fStream.Read(b, 0, ctype(fStream.L ength,int32))
> Response.Binary Write(b)
> Response.End()
> fStream.Close()
> fStream = Nothing
> "Dorsa" <do******@yahoo .com> wrote in message
> news:23******** *************** **@posting.goog le.com...
> > HI, Could you please tell me the error in here. I am trying to open an > > XML file from a link.
> >
> >
> > Response.Clear( )
> > Response.Expire s = 0
> > Response.Buffer Output = False
> > Response.Conten tType = "text/xml"
> > Response.AddHea der("Content-Disposition",
> > "filename=test. XML")
> >
> > Dim OStream As FileStream
> > Dim FileSize As Long
> > Dim ds As New DataSet()
> >
> > OStream = New FileStream(Serv er.MapPath("tes t.XML"),
> > FileMode.Open, FileAccess.Read )
> > ds.ReadXml(OStr eam)
> >
> > FileSize = OStream.Length
> > Dim Buffer(CInt(Fil eSize)) As Byte
> >
> > OStream.Read(Bu ffer, 0, CInt(FileSize))
> > OStream.Close()
> >
> > Response.Write( Buffer)
> > Response.End()

Nov 18 '05 #7
Yes, It worked. But here is the things that I'm not sure about that
and I got stuck and I couldn't find any solution for that. I'm pretty
sure that you can help me.
So right now, that XML file can be opend with word2003. it's only text
in that file but I need to treat it as an XML file. (word2003 saved as
XML)
I need to search and replace some text in it. here is an example. I
need to replace "test" with "test1" in "This is a test". Could you
tell me how I can do that? I'm have tried with fileStream and binary
reading but without any success.
I would be thankful if you could help me with that. I'm using vb.net
Thanks
Ayat
"vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.com> wrote in message news:<bs******* ***@ngspool-d02.news.aol.co m>...
Have you tried just a straight forward file write such as. You might also
want to mess with the ContentType

Dim fi as System.IO.FileI nfo = new System.IO.FileI nfo(youpathandf ilename)

Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/unknown"
Response.AddHea der("Content-Disposition", "attachment;fil ename=" +
filename)
Response.WriteF ile(fi.fullname )
Response.End()

fi = Nothing

"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** ***@posting.goo gle.com...
yes, there is an extra character at the end. I couldn't find the
reason and I also tried with other Response.Conten tType but seems that
it dosen't care what for that value. Do you any idea how I can delete
that character byte at the end after ">" ?
Also, Is there another way for getting my XML file into word? Can you
tell me about why you used binary for output?
Thanks
Dorsa
"vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.com> wrote in message

news:<bs******* ***@ngspool-d02.news.aol.co m>...
One other probably obvious thing is have you tried reopenning it with
Word2003 before it is downloaded to see that Word is creating a valid xml file. I read a few threads about it and it fairly new and there have been some problems with Word documents which contain grahics and other features.
"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** ***@posting.goo gle.com...
> 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.ge ZwaYrrenZ.com> wrote in message news:<bs******* ***@ngspool-d02.news.aol.co m>... > > Try something like this where pathfile is the path and file name of your > > file.
> >
> > Dim fStream As New System.IO.FileS tream(pathfile, IO.FileMode.Ope n,
> > IO.FileAccess.R ead, IO.FileShare.Re ad)
> > Dim b(ctype(fStream .Length,int32)) As Byte
> > Response.Clear( )
> > Response.ClearC ontent()
> > Response.ClearH eaders()
> > Response.Conten tType = "applicatio n/unknown"
> > Response.AddHea der("Content-Disposition", "attachment;fil ename=" + > > filename)
> > fStream.Read(b, 0, ctype(fStream.L ength,int32))
> > Response.Binary Write(b)
> > Response.End()
> > fStream.Close()
> > fStream = Nothing
> > "Dorsa" <do******@yahoo .com> wrote in message
> > news:23******** *************** **@posting.goog le.com...
> > > HI, Could you please tell me the error in here. I am trying to open an > > > XML file from a link.
> > >
> > >
> > > Response.Clear( )
> > > Response.Expire s = 0
> > > Response.Buffer Output = False
> > > Response.Conten tType = "text/xml"
> > > Response.AddHea der("Content-Disposition",
> > > "filename=test. XML")
> > >
> > > Dim OStream As FileStream
> > > Dim FileSize As Long
> > > Dim ds As New DataSet()
> > >
> > > OStream = New FileStream(Serv er.MapPath("tes t.XML"),
> > > FileMode.Open, FileAccess.Read )
> > > ds.ReadXml(OStr eam)
> > >
> > > FileSize = OStream.Length
> > > Dim Buffer(CInt(Fil eSize)) As Byte
> > >
> > > OStream.Read(Bu ffer, 0, CInt(FileSize))
> > > OStream.Close()
> > >
> > > Response.Write( Buffer)
> > > Response.End()

Nov 18 '05 #8
Well, if I understand what you are trying to do you would do something like
I have below, but there are better ways to do this if your original word
file is structured but you can give this a try. Typically you would go to a
node and change the node values but this should work.
Dim doc As XmlDocument = New XmlDocument()
doc.Load("yourp ath and file name.xml")
dim sb as new stringbuilder(d oc.innerxml,doc .innerxml.lengt h + 100)
sb.replace("old text","newtext" )
doc.innerXML = sb.tostring()
doc.save("yourp ath and file name.xml") 'note you may want to use a
different name for testing to see how it works

Good luck.

"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** ***@posting.goo gle.com...
Yes, It worked. But here is the things that I'm not sure about that
and I got stuck and I couldn't find any solution for that. I'm pretty
sure that you can help me.
So right now, that XML file can be opend with word2003. it's only text
in that file but I need to treat it as an XML file. (word2003 saved as
XML)
I need to search and replace some text in it. here is an example. I
need to replace "test" with "test1" in "This is a test". Could you
tell me how I can do that? I'm have tried with fileStream and binary
reading but without any success.
I would be thankful if you could help me with that. I'm using vb.net
Thanks
Ayat
"vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.com> wrote in message

news:<bs******* ***@ngspool-d02.news.aol.co m>...
Have you tried just a straight forward file write such as. You might also want to mess with the ContentType

Dim fi as System.IO.FileI nfo = new System.IO.FileI nfo(youpathandf ilename)
Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/unknown"
Response.AddHea der("Content-Disposition", "attachment;fil ename=" +
filename)
Response.WriteF ile(fi.fullname )
Response.End()

fi = Nothing

"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** ***@posting.goo gle.com...
yes, there is an extra character at the end. I couldn't find the
reason and I also tried with other Response.Conten tType but seems that
it dosen't care what for that value. Do you any idea how I can delete
that character byte at the end after ">" ?
Also, Is there another way for getting my XML file into word? Can you
tell me about why you used binary for output?
Thanks
Dorsa
"vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.com> wrote in message

news:<bs******* ***@ngspool-d02.news.aol.co m>...
> One other probably obvious thing is have you tried reopenning it with > Word2003 before it is downloaded to see that Word is creating a valid
xml
> file. I read a few threads about it and it fairly new and there have

been
> some problems with Word documents which contain grahics and other

features.
>
> "Dorsa" <do******@yahoo .com> wrote in message
> news:23******** *************** ***@posting.goo gle.com...
> > 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.ge ZwaYrrenZ.com> wrote in message news:<bs******* ***@ngspool-d02.news.aol.co m>...
> > > Try something like this where pathfile is the path and file name
of your
> > > file.
> > >
> > > Dim fStream As New System.IO.FileS tream(pathfile,
IO.FileMode.Ope n, > > > IO.FileAccess.R ead, IO.FileShare.Re ad)
> > > Dim b(ctype(fStream .Length,int32)) As Byte
> > > Response.Clear( )
> > > Response.ClearC ontent()
> > > Response.ClearH eaders()
> > > Response.Conten tType = "applicatio n/unknown"
> > > Response.AddHea der("Content-Disposition", "attachment;fil ename=" +
> > > filename)
> > > fStream.Read(b, 0, ctype(fStream.L ength,int32))
> > > Response.Binary Write(b)
> > > Response.End()
> > > fStream.Close()
> > > fStream = Nothing
> > > "Dorsa" <do******@yahoo .com> wrote in message
> > > news:23******** *************** **@posting.goog le.com...
> > > > HI, Could you please tell me the error in here. I am trying to

open an
> > > > XML file from a link.
> > > >
> > > >
> > > > Response.Clear( )
> > > > Response.Expire s = 0
> > > > Response.Buffer Output = False
> > > > Response.Conten tType = "text/xml"
> > > > Response.AddHea der("Content-Disposition",
> > > > "filename=test. XML")
> > > >
> > > > Dim OStream As FileStream
> > > > Dim FileSize As Long
> > > > Dim ds As New DataSet()
> > > >
> > > > OStream = New

FileStream(Serv er.MapPath("tes t.XML"), > > > > FileMode.Open, FileAccess.Read )
> > > > ds.ReadXml(OStr eam)
> > > >
> > > > FileSize = OStream.Length
> > > > Dim Buffer(CInt(Fil eSize)) As Byte
> > > >
> > > > OStream.Read(Bu ffer, 0, CInt(FileSize))
> > > > OStream.Close()
> > > >
> > > > Response.Write( Buffer)
> > > > Response.End()

Nov 18 '05 #9
Appreciate it Mike. You helped me a lot. I like to way you wrote it
and it works perfectly.I wanted to show you my code and ask your idea
about it.
Please read my code below. It works, but I found out that when there
is a comma in my text (not the text that I'm searching for) it changes
into some strange character. I also read about stringBulider and I
found out that whenever that we use one of the methods, we create a
new string object in the memory which requires a new allocation of
space. Since this search and replace is a daily routine and there are
more than 100 documents in near future, should I be worry about Memory
and related issues?
Thanks
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Dim result, str As String
Dim xml As New XmlDocument()
Dim oStream As FileStream
Dim fStream As New
System.IO.FileS tream(Server.Ma pPath("test.xml "), IO.FileMode.Ope n,
IO.FileAccess.R ead, IO.FileShare.Re ad)

Dim byteArray(CType (fStream.Length - 1, Int32)) As Byte
fStream.Read(by teArray, 0, CInt(fStream.Le ngth))

Dim i As Integer

For i = 0 To byteArray.Lengt h - 1
str &= Chr(byteArray(i ))
Next

result = Replace(str, "test", "test1")

Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/x-msdownload"
Response.AddHea der("Content-Disposition",
"attachment;fil ename=" + "test.xml")
Response.Write( result)
fStream.Close()
Response.End()

fStream = Nothing

End Sub

"vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.com> wrote in message news:<bt******* ***@ngspool-d02.news.aol.co m>...
Well, if I understand what you are trying to do you would do something like
I have below, but there are better ways to do this if your original word
file is structured but you can give this a try. Typically you would go to a
node and change the node values but this should work.
Dim doc As XmlDocument = New XmlDocument()
doc.Load("yourp ath and file name.xml")
dim sb as new stringbuilder(d oc.innerxml,doc .innerxml.lengt h + 100)
sb.replace("old text","newtext" )
doc.innerXML = sb.tostring()
doc.save("yourp ath and file name.xml") 'note you may want to use a
different name for testing to see how it works

Good luck.

"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** ***@posting.goo gle.com...
Yes, It worked. But here is the things that I'm not sure about that
and I got stuck and I couldn't find any solution for that. I'm pretty
sure that you can help me.
So right now, that XML file can be opend with word2003. it's only text
in that file but I need to treat it as an XML file. (word2003 saved as
XML)
I need to search and replace some text in it. here is an example. I
need to replace "test" with "test1" in "This is a test". Could you
tell me how I can do that? I'm have tried with fileStream and binary
reading but without any success.
I would be thankful if you could help me with that. I'm using vb.net
Thanks
Ayat
"vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.com> wrote in message

news:<bs******* ***@ngspool-d02.news.aol.co m>...
Have you tried just a straight forward file write such as. You might also want to mess with the ContentType

Dim fi as System.IO.FileI nfo = new System.IO.FileI nfo(youpathandf ilename)
Response.Clear( )
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/unknown"
Response.AddHea der("Content-Disposition", "attachment;fil ename=" +
filename)
Response.WriteF ile(fi.fullname )
Response.End()

fi = Nothing

"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** ***@posting.goo gle.com...
> yes, there is an extra character at the end. I couldn't find the
> reason and I also tried with other Response.Conten tType but seems that
> it dosen't care what for that value. Do you any idea how I can delete
> that character byte at the end after ">" ?
> Also, Is there another way for getting my XML file into word? Can you
> tell me about why you used binary for output?
> Thanks
> Dorsa
>
>
> "vMike" <Mi************ ****@noYandZ.ge ZwaYrrenZ.com> wrote in message news:<bs******* ***@ngspool-d02.news.aol.co m>... > > One other probably obvious thing is have you tried reopenning it with > > Word2003 before it is downloaded to see that Word is creating a valid
xml > > file. I read a few threads about it and it fairly new and there have been > > some problems with Word documents which contain grahics and other features. > >
> > "Dorsa" <do******@yahoo .com> wrote in message
> > news:23******** *************** ***@posting.goo gle.com...
> > > 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.ge ZwaYrrenZ.com> wrote in message
news:<bs******* ***@ngspool-d02.news.aol.co m>... > > > > Try something like this where pathfile is the path and file name of
your > > > > file.
> > > >
> > > > Dim fStream As New System.IO.FileS tream(pathfile, IO.FileMode.Ope n, > > > > IO.FileAccess.R ead, IO.FileShare.Re ad)
> > > > Dim b(ctype(fStream .Length,int32)) As Byte
> > > > Response.Clear( )
> > > > Response.ClearC ontent()
> > > > Response.ClearH eaders()
> > > > Response.Conten tType = "applicatio n/unknown"
> > > > Response.AddHea der("Content-Disposition", "attachment;fil ename="
+ > > > > filename)
> > > > fStream.Read(b, 0, ctype(fStream.L ength,int32))
> > > > Response.Binary Write(b)
> > > > Response.End()
> > > > fStream.Close()
> > > > fStream = Nothing
> > > > "Dorsa" <do******@yahoo .com> wrote in message
> > > > news:23******** *************** **@posting.goog le.com...
> > > > > HI, Could you please tell me the error in here. I am trying to open an > > > > > XML file from a link.
> > > > >
> > > > >
> > > > > Response.Clear( )
> > > > > Response.Expire s = 0
> > > > > Response.Buffer Output = False
> > > > > Response.Conten tType = "text/xml"
> > > > > Response.AddHea der("Content-Disposition",
> > > > > "filename=test. XML")
> > > > >
> > > > > Dim OStream As FileStream
> > > > > Dim FileSize As Long
> > > > > Dim ds As New DataSet()
> > > > >
> > > > > OStream = New FileStream(Serv er.MapPath("tes t.XML"), > > > > > FileMode.Open, FileAccess.Read )
> > > > > ds.ReadXml(OStr eam)
> > > > >
> > > > > FileSize = OStream.Length
> > > > > Dim Buffer(CInt(Fil eSize)) As Byte
> > > > >
> > > > > OStream.Read(Bu ffer, 0, CInt(FileSize))
> > > > > OStream.Close()
> > > > >
> > > > > Response.Write( Buffer)
> > > > > Response.End()

Nov 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
587
by: Pankaj Garg | last post by:
I have written a program, where I download reports in PDF or Excel format, depends on user selection. My code is working fine for PDF format, but same code os not working for excel file. When I execute the code, A dialog box appears, itr shows the file name that is same as my aspx file name, with aspx extension (like showreport.aspx), instead of xls extension. I have also verified valid excel file exists at that location from where I am...
6
32173
by: Fredrik | last post by:
How can I download a binary file (like .doc or .pdf) from http to my harddrive using the .net framework? WebRequest objRequest = System.Net.HttpWebRequest.Create(url); objResponse = objRequest.GetResponse(); BinaryReader bsRead = new BinaryReader(objResponse.GetResponseStream() FileStream fs = new FileStream("test.doc", FileMode.CreateNew); while(bsRead.PeekChar() != -1) { cbuf=bsRead.ReadByte();
5
5284
by: Baren | last post by:
Hi! I am using impersonate="true" to upload and download files from a network share. I have created common users on both the webserver and the file server. The user has permission to the files server folder. I am able to upload the files into the fileserver, but while downloading the same i am getting error "file doesn't exist" and the path it shows is localhost temporary internet files.
1
1908
by: Bala | last post by:
Hi When the user clicks the download button on my aspx page, the file (pdf) downloaded from my server another drive. Once he clicks the button, I inserted the record on one of table. after that the IE will ask do you want to open or cancel, the user may click cancel button. so in this situtation, i need to insert the record on table once the user click save button. if the user clicks the cancel, I should not insert the records. how to...
4
2712
by: Benny Raymond | last post by:
I've nearly finished my personal auto updater and the only thing left to implement is a hash check against the downloaded file to make sure it's good before extracting it. Right now I havn't released it so I've tested that the selected update components download correctly and extract and that the program starts back up as the new version... I've googled for about a half hour and couldn't figure out how to generate an MD5 hash for both...
3
2739
by: Tom | last post by:
I'm wiritng a dot.net windows forms appliction that needs to connect to a webservice to download some files. I need to show a progress bar during the download, bacause some file can be very big. How Can i Mkae this? Can i use a stream? There are some samples? I'm thinking to use a byte array to get, for each call, a chunck of bytes, but I think also that in this way i'll made a lot of HTTP calls...
0
1636
by: Tim Cowan | last post by:
Hi, I am using this code to download files on VS 2005. It downloads the file but waits until the timeout (which is why it is so short) to add the last 4 bytes or so. It always returns a WebException which most of the time is just feedback from the FTP server, so how do I tell if the download was successful/complete or not? Tim
1
1431
by: Carlo | last post by:
I am trying to seek the following functionality: A user clicks on a download buton I can automatically download a file, but since in the end i must end the response, its either the download or the page display. To dowload the file i am using the following code: Response.ContentType = "application\\octet-stream";
0
5252
by: Tifer | last post by:
Hello, I am building my first .Net Application. The first couple of Publish and Installs I did went fine. But after a couple of builds, I get a modal dialogue box error every time upon trying to install using the setup.exe. Title is "Cannot Start Application" and it says: ==================== Cannot download the application. The application is missing required files. Contact application vendor for assistance.
0
8896
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9653
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9451
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8328
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4771
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4942
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3395
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2872
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2284
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.