PC Review


Reply
Thread Tools Rate Thread

Create word doc from a memory stream NO file stream used

 
 
Nitin Mahajan
Guest
Posts: n/a
 
      24th Jul 2008
Guys

Is there a way in C# to create a word object directly from a memory
stream without passing that to hard disk (file stream). I think it
doesn't makes sense to create a file just to read it again in to word
object. If some one has some brilliant idea please share.

In a nutshell this is what I'm currently doing
ByteArray --> File Stream --> Word Object
and this I want to do
ByteArray --> Memory Stream --> Word Object


thanks
nitin

 
Reply With Quote
 
 
 
 
raylopez99
Guest
Posts: n/a
 
      24th Jul 2008
On Jul 24, 5:13*am, Nitin Mahajan <nitinhung...@gmail.com> wrote:
> Guys
>
> Is there a way in C# to create a word object directly from a memory
> stream without passing that to hard disk (file stream). I think it
> doesn't makes sense to create a file just to read it again in to word
> object. If some one has some brilliant idea please share.
>
> In a nutshell this is what I'm currently doing
> ByteArray --> File Stream --> Word Object
> and this I want to do
> ByteArray --> Memory Stream --> Word Object
>
> thanks
> nitin


There is a way. I've seen this in C++ code on somebody's blog a while
ago--it was too speed up the app for performance, as the bytearray was
streaming in from a port connected to the internet. I just don't have
a solution offhand right now. One way, however, that might work for
you is in the C#3.0 Cookbook (O'Reilly). Keywords: redirection,
RedirectStandardOutput property of the Process.StartInfo class, also
look to recipe 12.20, writing to multiple output files at one time.

Hope this helps...

RL
 
Reply With Quote
 
jake
Guest
Posts: n/a
 
      24th Jul 2008
I did something similar to this. I created an xml document, not word
document, using the StringReader class. It creates a memory stream
from a string, and I was able to substitute it into anywhere a file
stream was required.
Hope this helps.
jake


On Jul 24, 8:13 am, Nitin Mahajan <nitinhung...@gmail.com> wrote:
> Guys
>
> Is there a way in C# to create a word object directly from a memory
> stream without passing that to hard disk (file stream). I think it
> doesn't makes sense to create a file just to read it again in to word
> object. If some one has some brilliant idea please share.
>
> In a nutshell this is what I'm currently doing
> ByteArray --> File Stream --> Word Object
> and this I want to do
> ByteArray --> Memory Stream --> Word Object
>
> thanks
> nitin


 
Reply With Quote
 
Nitin Mahajan
Guest
Posts: n/a
 
      28th Jul 2008
On Jul 24, 6:44*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> On Thu, 24 Jul 2008 05:13:41 -0700,NitinMahajan<nitinhung...@gmail.com> *
> wrote:
>
> > Guys

>
> > Is there a way in C# to create a word object directly from a memory
> > stream without passing that to hard disk (file stream). I think it
> > doesn't makes sense to create a file just to read it again in to word
> > object. If some one has some brilliant idea please share.

>
> > In a nutshell this is what I'm currently doing
> > ByteArray --> File Stream --> Word Object
> > and this I want to do
> > ByteArray --> Memory Stream --> Word Object

>
> No "brilliant idea". *Just replace your FileStream instance with a *
> MemoryStream instance, simple as that.
>
> Ideally, your code would have created a FileStream but used it just as a *
> Stream. *If so, it's a simple one-line change. *If you declared your *
> stream usage as FileStream and then used something that's actually *
> declared only in the FileStream class, you might have a little extra *
> work. *But that's probably not the case.
>
> Pete


Pete

I dont think it will work because I'm currently using .net 1.1 and
they way the word object can be created is creating a word document
from a file stream and then using that word doc. Now the problem is I
dont want to create a word document physically on the hard disk. I
want to create the word object directly from bytearray as the word
document is stored as blob in database.

Also its a different case from creating XML as in .net there is
inbuilt support for XML but not for word.

I hope I'm clear this time. In anycase thanks for your help.

cheers
nitin
 
Reply With Quote
 
raylopez99
Guest
Posts: n/a
 
      28th Jul 2008
On Jul 28, 2:42*am, Nitin Mahajan <nitinhung...@gmail.com> wrote:
>
> I dont think it will work because I'm currently using .net 1.1 and
> they way the word object can be created is creating a word document
> from a file stream and then using that word doc.


Try upgrading to 3.0--the express version is free. Then try it and
see if it solves your problem.

RL
 
Reply With Quote
 
Nitin
Guest
Posts: n/a
 
      29th Jul 2008
On Jul 28, 6:55*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> On Mon, 28 Jul 2008 02:42:12 -0700,NitinMahajan<nitinhung...@gmail.com> *
> wrote:
>
> > I dont think it will work because I'm currently using .net 1.1 and
> > they way the word object can be created is creating a word document
> > from a file stream and then using that word doc.

>
> Well, that's not the question you asked. *_Creating_ the Word document,as *
> you asked, can be done just as has been suggested. *But yes, if you want *
> to _use_ the document in Word, you need some way of getting that data to *
> Word. *Unfortunately, as far as I know Word offers no memory-based API to *
> load a document. *It has to come from a file. *And I'm not aware of any *
> API that would virtualize a block of memory as a file per se.
>
> You might want to look at the unmanaged Windows API, and see if the *
> memory-mapped file i/o might suit your purposes. *You'd have to use *
> p/invoke in order to write to the memory-mapped file object. *I don't *
> recall off the top of my head whether you can create a memory-mapped file*
> that is backed only by the swap-file, but if you can that might do what *
> you want.
>
> Personally, I think you're probably overthinking the problem. *Creatinga *
> temporary file and letting Word read it seems like a fine solution to me.*
> It's the exact model used by all sorts of other programs (including email*
> programs opening file attachments).
>
> Pete


I guess you are right. I was just checking if there are other ways to
achieve this...
In any case thanks a lot your help.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stream To Memory Stream Error rh1200la@gmail.com Microsoft Dot NET 6 25th Oct 2006 10:03 PM
Want to create either a stream or a file Steve Microsoft C# .NET 1 14th Dec 2005 12:04 AM
File to Memory stream Robert Strickland Microsoft C# .NET 6 25th May 2005 01:48 PM
MEmory stream, file stream Pums Microsoft C# .NET 4 11th Dec 2003 11:46 AM
Retrieving file name from memory stream? Klaus Enevoldsen Microsoft Dot NET Framework 1 3rd Dec 2003 12:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:38 AM.