Launch Browser and pass parameters.
-
I have windows app and am using c#. I want to launch default browser from c# program and pass some parameters. Basically what i have is content type (eg. "application/msword") and byte array of content (word/excel/pdf docs in byte array). I want to pass these two parameters to browser and let it open the doc. Can anybody please guide me to achieve this? One more thing i don't want to create any file in local disk. Thanks.
-
I have windows app and am using c#. I want to launch default browser from c# program and pass some parameters. Basically what i have is content type (eg. "application/msword") and byte array of content (word/excel/pdf docs in byte array). I want to pass these two parameters to browser and let it open the doc. Can anybody please guide me to achieve this? One more thing i don't want to create any file in local disk. Thanks.
Are you saying the document is not on your disk or some remote machine, but in memory? If yes, simply save it to a temporary location and display it from there. That is what even browsers do. Once you've saved it, try
Process.Start("URL of your document")
. That will open the default handler (generally, MS Word) though. Launching a local .DOC file with your default browser might be slightly more complicated, and I'm not even sure why you'd want to do that.Cheers, Vikram. (Proud to have finally cracked a CCC!)
-
Are you saying the document is not on your disk or some remote machine, but in memory? If yes, simply save it to a temporary location and display it from there. That is what even browsers do. Once you've saved it, try
Process.Start("URL of your document")
. That will open the default handler (generally, MS Word) though. Launching a local .DOC file with your default browser might be slightly more complicated, and I'm not even sure why you'd want to do that.Cheers, Vikram. (Proud to have finally cracked a CCC!)
Thanks Vikram, here are my problems: 1. I actually don't want to store doc in local machine and handle creation and deletion of files. If in any case end user have very minimum rights i may not be able to create file even. Here maybe i should think of memory stream? 2. "Launching a local .DOC file with your default browser might be slightly more complicated, and I'm not even sure why you'd want to do that. " i din't get this? Are you suggesting to launch directly ms word, excel or acrobat softwares and display docs in them instead of using browser? if yes, the problem with this approach is i need to know and code for all types of docs, if i use browser i no need to bother about this as far as i supply content type and byte array. Thanks.
-
Thanks Vikram, here are my problems: 1. I actually don't want to store doc in local machine and handle creation and deletion of files. If in any case end user have very minimum rights i may not be able to create file even. Here maybe i should think of memory stream? 2. "Launching a local .DOC file with your default browser might be slightly more complicated, and I'm not even sure why you'd want to do that. " i din't get this? Are you suggesting to launch directly ms word, excel or acrobat softwares and display docs in them instead of using browser? if yes, the problem with this approach is i need to know and code for all types of docs, if i use browser i no need to bother about this as far as i supply content type and byte array. Thanks.
Member 2324483 wrote:
If in any case end user have very minimum rights i may not be able to create file even. Here maybe i should think of memory stream?
AFAIK, *every* user will have read + write access to a temp directory. Path.GetTempPath() is your friend. I doubt Word can handle in-memory files.
Member 2324483 wrote:
Are you suggesting to launch directly ms word, excel or acrobat softwares and display docs in them instead of using browser? if yes, the problem with this approach is i need to know and code for all types of docs, if i use browser i no need to bother about this as far as i supply content type and byte array.
Yes, that's what I suggest and it's the cleanest and the easiest. You don't have to handle any extra types,
Process.Start("yourfile")
will open it with the default program. It's opening with the default browser that is dubious.Cheers, Vikram. (Proud to have finally cracked a CCC!)