locked
memory stream RRS feed

  • Question

  • Hi guys.I wanna learn that; Can i start a file with Diagnostic.Process function with memorystream ? For example i have a file in memorystream(mp3 file) and i wanna process it file with associated program(Media Player)? some file type-> html->ie txt->notepad mp3->MediaPlayer jpg->Office Picture manager Is there anybody has good idea? i musnt use harddrive...
    www.hasan-bozkurt.blogspot.com
    Wednesday, October 19, 2011 2:22 PM

Answers

  • If I understand you right, you could solve your problem with an approach from the old DOS days: Simply use a RAM-Drive - it pretends to be a "usual" disk drive but keeps data only in memory. Search for "ramdisk" and "dataram". You can emulate a disk with up to 4 GByte memory ..

    Cheers,
    Stefan

     

    • Marked as answer by kodpark Friday, October 21, 2011 11:27 AM
    Thursday, October 20, 2011 11:16 AM
  • OK, when you ask whether you will be able to develop a ramdrive - you most likly won't be. I think that will be rather complex, you need to now about Windows driver development, file systems etc.

    I would also recommend to use a ramdrive that is available of the shelf. The mentioned "Dataram" ramdrive is freeware and supports a lot of different Windows systems. So I put a link here, but I am not in anyway connected to "Dataram" : http://memory.dataram.com/products-and-services/software/ramdisk

    Best regards,

    Stefan

     

    • Marked as answer by kodpark Friday, October 21, 2011 11:26 AM
    Thursday, October 20, 2011 12:04 PM
  • Okay, that should be a peace of cake:

    1. Install the ramdrive and assign a drive letter, like "R:"
    2. Copy the file to the ramdrive as you would do so for a "real" harddrive, e.g. copy C:\temp\document.pdf R:\temp
    3. Call the method System.Diagnostics.Process.Start() like this --> System.Diagnostics.Process.Start(@"R:\temp\document.pdf");

    Step no. 3 should launch the associated PDF-Reader. And when the systems shuts down all content of the Ramdrive is lost ..

     

    Hope that helps,

    Stefan

     



     

    • Marked as answer by kodpark Friday, October 21, 2011 11:27 AM
    Thursday, October 20, 2011 11:53 AM

All replies

  • It depends on the program that you use to open the file. For example, if you reference MediaPlayer's COM component in your application and the interface supports an Open(...) method that can take a Stream then you can open the file directly from MemoryStream.

    You can do that with HTML->IE. With the WebBrowser control in WinForms, use the DocumentStream property to set the current document.


    Click the 'Vote as Helpful' arrow if this post was helpful.
    Wednesday, October 19, 2011 2:31 PM
  • A memorystream exist inside your program it is not a kind of pipeline (remoting) to another program. 

    For an associated program you simply need a file which has an extension like it is set in the OS. 


    Success
    Cor
    Wednesday, October 19, 2011 2:40 PM
  • Abhimanyu Sirohi thanks for your replay...

    i was very angry....now i hope to solve...

    Can you give any code example?

    also i need open all file type

    pdf,doc,mp3,vcd,nrg,iso,xls,jpg,mp3,gif,wav, all file type i must open without saving harddrive...Can u give sample code  ?

    thanks a lot


    www.hasan-bozkurt.blogspot.com
    Wednesday, October 19, 2011 3:35 PM
  • Cor thanks.For example i write a file to memorystream...this file is pdf file and associated adobe reader program.Can  i open this file without saving harddrive?Do you sugges another way?

    www.hasan-bozkurt.blogspot.com
    Wednesday, October 19, 2011 3:45 PM
  • is there any good idea?

    www.hasan-bozkurt.blogspot.com
    Wednesday, October 19, 2011 8:27 PM
  • Here's a example with WebBrowser control:

    using (FileStream sr = new FileStream(@"c:\test.html", FileMode.Open))
    {
        byte[] buffer = new byte[sr.Length];
        sr.Read(buffer, 0, (int)sr.Length);
    
        MemoryStream ms = new MemoryStream(buffer);
        webBrowser1.DocumentStream = ms;
    
        while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
            Application.DoEvents();
    }
    

    For other files, you need to find the components that you can use to load them.

     


    Click the 'Vote as Helpful' arrow if this post was helpful.
    Thursday, October 20, 2011 5:36 AM
  • i understand you and thanks a lot.

    my second question is can we open a file without saving harddrive?Can you give an answer?


    www.hasan-bozkurt.blogspot.com
    Thursday, October 20, 2011 10:19 AM
  • The above reply show how to use MemoryStream to load document in WebBrowser. The FileStream object is just used to fill in the MemoryStream, you will have a different way of creating your MemoryStream object. So this is the code that you need after filling the "buffer" variable with your data:

    MemoryStream ms = new MemoryStream(buffer);
        webBrowser1.DocumentStream = ms;
    
        while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
            Application.DoEvents();
    


    Click the 'Vote as Helpful' arrow if this post was helpful.
    Thursday, October 20, 2011 10:23 AM
  • no you didnt understand me...because i mean other file types...for example pdf,wav,ppt and all file types ...i cannot find com object all file types.Because of that i must open it associated program.as System.diagnostic.process.start(...)  code i need it...Do you understand me ?

    www.hasan-bozkurt.blogspot.com
    Thursday, October 20, 2011 10:28 AM
  • I do not think that is possible. Process.Start(...) calls the executable with specified arguments as string which are then passed to the executable as command line options. I don't think you can pass a MemoryStream as command line argument to an executable.
    Click the 'Vote as Helpful' arrow if this post was helpful.
    Thursday, October 20, 2011 10:32 AM
  • it doesnt be has to process.start code...i m searching another way without saving harddrive.Because i m developing a program working in ram  because of that i need without saving harddrive i must open it.Already i was thinking you said way but it way very hard and long...

    i thinking so way....for example pdf file... i m using adobe reader... i will start adobe reader and i will send  file that is in memorystream as parameter and it will be open ?Do you think is this possible ?and can we provide for all file types?


    www.hasan-bozkurt.blogspot.com

    • Edited by kodpark Thursday, October 20, 2011 10:45 AM
    Thursday, October 20, 2011 10:38 AM
  • I understand but how will you send memorystream as parameter to Adobe Reader? That is only possible when you are using the Adobe Reader ActiveX Control (COM Control) and it supports opening file from a Stream.
    Click the 'Vote as Helpful' arrow if this post was helpful.
    Thursday, October 20, 2011 10:52 AM
  • In my opinion you can never influence the way a program behaves, if the creator of that program not has created some special ways.

    I've not the idea there is interop with .Net available for adobe reader. 

    For the simple solutions like that there is the clipboard, but then still you should in a way be able to create a mechanism in the retrieving program.

    http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard.aspx


    Success
    Cor
    Thursday, October 20, 2011 11:01 AM
  • If I understand you right, you could solve your problem with an approach from the old DOS days: Simply use a RAM-Drive - it pretends to be a "usual" disk drive but keeps data only in memory. Search for "ramdisk" and "dataram". You can emulate a disk with up to 4 GByte memory ..

    Cheers,
    Stefan

     

    • Marked as answer by kodpark Friday, October 21, 2011 11:27 AM
    Thursday, October 20, 2011 11:16 AM

  • Stefan yes you understand me correctly bu i dont  have any info  to solve...Yes i have enoughly ram space...and i wanna use ram pretends to be disk drive...and i want open file associated with program....doc ->word ppt->power point wav->media player pdf->adobe etc. and all file types...can you help me?


    www.hasan-bozkurt.blogspot.com
    • Edited by kodpark Thursday, October 20, 2011 11:42 AM
    Thursday, October 20, 2011 11:41 AM
  • Okay, that should be a peace of cake:

    1. Install the ramdrive and assign a drive letter, like "R:"
    2. Copy the file to the ramdrive as you would do so for a "real" harddrive, e.g. copy C:\temp\document.pdf R:\temp
    3. Call the method System.Diagnostics.Process.Start() like this --> System.Diagnostics.Process.Start(@"R:\temp\document.pdf");

    Step no. 3 should launch the associated PDF-Reader. And when the systems shuts down all content of the Ramdrive is lost ..

     

    Hope that helps,

    Stefan

     



     

    • Marked as answer by kodpark Friday, October 21, 2011 11:27 AM
    Thursday, October 20, 2011 11:53 AM
  • oooo it is very helpful...i really liked this answer....Do you sugges any ram drive program?and am i able to develope it?in fact i dont know anything about ram drive...How can i do?Please help me...i m sorry because i dont know anything ....and thanks a lot...

    best regards


    www.hasan-bozkurt.blogspot.com
    Thursday, October 20, 2011 11:57 AM
  • OK, when you ask whether you will be able to develop a ramdrive - you most likly won't be. I think that will be rather complex, you need to now about Windows driver development, file systems etc.

    I would also recommend to use a ramdrive that is available of the shelf. The mentioned "Dataram" ramdrive is freeware and supports a lot of different Windows systems. So I put a link here, but I am not in anyway connected to "Dataram" : http://memory.dataram.com/products-and-services/software/ramdisk

    Best regards,

    Stefan

     

    • Marked as answer by kodpark Friday, October 21, 2011 11:26 AM
    Thursday, October 20, 2011 12:04 PM
  • A Ram drive is nothing else then assigning a part of the memory as disk.

    It has probably not any advantage over well using a temp file. The speed of a disk is not anymore like in the days of the floppy disk when the Ram drive was invented.

    (It was also meant to enable the non addressable memory above the 1Mb area on a x86 system)

    Be aware in current Windows beside in some cases with a special option in 32bit above 2Gb where only .Net programs are used, it direct influences always the available memory of the enduser.

     


    Success
    Cor


    Friday, October 21, 2011 5:20 AM
  • hi guys thanks a lot all of you...And i have found how to solve this problem thanks to you...

    and i need ram disk component free && cheap....or program that will be managed from my program... which do you recommend

    Best regards


    www.hasan-bozkurt.blogspot.com
    • Edited by kodpark Friday, October 21, 2011 11:28 AM
    Friday, October 21, 2011 11:26 AM