473,769 Members | 5,836 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
11 4046
The Problem is not "," infact is "'" in my file.
"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 #11
I am glad you got it working. You might want to take another look at the
stringbuilder info as regards to memory. As I understand it, any time you
change a string, a new string must be created in memory and the old string's
memory is released. The stringbuilder class using the same memory as long as
the size of the "string" isn't greater that the capacity when it is created.
I have never done any tests so I am not sure which is better to use, but
generally if I have a lot of concatenation and/or replacing I prefer the
stringbuilder versus a string, but if I am doing simple string manipulation
I use the string class.

As far as the strange characters, I am not sure but some characters have
special meaning in xml files so that they have to be escaped or otherwise
changed to work correctly. That my be the case in your situation, but if it
works I would worry about it. I would test it with a lot of different
characters like & and > etc to make sure it works.
Good luck/.
"Dorsa" <do******@yahoo .com> wrote in message
news:23******** *************** ***@posting.goo gle.com...
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 #12

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
5285
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
1909
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
2740
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
1432
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
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9416
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
10199
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
10032
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...
1
7393
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
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...
1
3948
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
3551
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.