Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Using Word Automation with docs stored in database

Hi everybody !

I have to find out a solution on the following problem :
I've got a .NET application running on a server. This application has no file access. Notice this, it is the main problem.
This application uses a SQLServer table where documents can be saved as Image Datatype.

This application creates a Word document, saves it into the database, and then quits the Word component without saving the document (remember, no file access).

The problem is the second functionnality : I need to reach the document in the database, and edit it with the word automation.
I know how to reach the file, and write it on the HDD using filestream, or put it into the memory using memorystream.
But, as I said before, I have no file access rights, and I can't find out how to open a Word document since the Documents.Add method waits for a full path...

Does anyone know how I could get out of this hell ?

Thanks by advance to anyone who reached the end of this text ;)

Thursday, May 22, 2003

How was the application able to save the Word BLOBs to the database in the first place? Surely it had to hit the filesystem first?

We write to %TEMP% in these situations: we do this for something which we need to serialise to the filesystem first:
string filename =  Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString());

Or has %TEMP% been locked down too?

Duncan Smart
Thursday, May 22, 2003

To save the document, I can save it using memorystream without accessing the file system, which works well... Thus, I thought there might be a solution to open the file without accessing the filesystem. :/

By now I use the temp directory with a GUID based filename.

But as to me, this is not very smart, since I have to let the writing rights to the application, at least on the temp directory.

Anyway, I think I'll have to make up with this.

Thanks Duncan.

Thursday, May 22, 2003

Use Isolated Storage.  It gives you a whole virtual file system to play with.  You'll need IsolatedStorageFilePermission to write files to it, but this is much safer than access to the real file system.  Check out the System.IO.IsolatedStorage namespace for more.  Not sure if Word can be pointed to it though...

Friday, May 23, 2003

You can also use WebDAV to access the file through a standard HTTP filestream.

Tuesday, June 24, 2003

*  Recent Topics

*  Fog Creek Home