I'm having trouble understanding how to update a PDF file in a FileTable using SqlFileStream and am hoping someone here can help. I think I just need an overview of how this is accomplished.

In my forms application I'm retrieving the PDF with READ access and displaying it in a PDF control through/using MemoryStream.

After adding some annotations to the PDF file I want to save/update the PDF file, and this is where I get lost. Since the PDF file has been opened with READ access I'm guessing I'd have to open another stream with WRITE access but I don't know how this is done. Basically, I'd like to overwrite an existing PDF file in the database.

Thank you for any help/guidance,
Matt

Thanks for the information. That's good to know.

Does this approach make updating an existing file in the database easier?

I tried this in my SQL Management console query window and it worked.

UPDATE PDFStore
   SET Contents = (SELECT  * FROM OPENROWSET(BULK 'D:\test.pdf', SINGLE_BLOB) SOMEALIAS)
WHERE FileName = 'D:\test.pdf'

I see in your example that you're working from the file system.

I'm still wrapping my arms around saving/updating files in a database, so pardon my ignorance, but does this assume that the file has first been saved to the file system (from the database)?

Or is your example with FileTables in mind?

I don't understand what you mean by FileTables. I know what a file is, and what a table is, but not a FileTable. Yes, my example requires the PDF to be in a file, however, it may be possible to create that file in memory rather than to disk. I'm not particularly interested in researching this so feel free, however, in the absence of a memory-based file you could always use the %TEMP% folder for such an operation.

This article has been dead for over six months. Start a new discussion instead.