|
-
Apr 15th, 2010, 01:55 PM
#6
Re: Stroning Excel, Word, and PDF docs in your program
ok, well one of the things to worry about is the fact that you are storing multiple types of files. When you add a file as a resource to a project, it strips the file type from it, and stores it as just an array of bytes. It doesn't care what type of file it is, but you do since you need to open a word document in word, or a PDF in adobe, etc...
So for the example, lets say I add a PDF to the project resources, and the PDF is called sample.pdf
When I add this to the resources, it is going to just call it 'sample'.
My suggestion would be to append the file extension to the name. You can't use periods, so use something like an underscore. So the resource name of 'sample' would be renamed by you to 'sample_pdf'. This will help when it comes time to figure out what type of file it is.
Then when you actually want to display the document via code, you just need to know what the original file name is that you want to show, and grab the resource file that matches, and write it out to a temp folder and launch it. Here is some sample code:
Code:
'THE DOCUMENT WE WANT TO LOAD
Dim myDocumentName As String = "sample.pdf"
'THE NAME OF THE RESOURCE THAT REPRESENTS THIS DOCUMENT (REPLACE _ WITH . TO MAKE VALID FILE NAME)
Dim myResourceName As String = myDocumentName.Replace(".", "_")
'TEMP FILE NAME
Dim myTempFileName As String = IO.Path.Combine(IO.Path.GetTempPath, myDocumentName)
'WRITE TEMP FILE TO DISK
My.Computer.FileSystem.WriteAllBytes(myTempFileName, CType(My.Resources.ResourceManager.GetObject(myResourceName), Byte()), False)
'LAUNCH TEMP FILE
If IO.File.Exists(myTempFileName) Then
Process.Start(myTempFileName)
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|