locked
add .cab file as an embedded resource RRS feed

  • Question

  • Can i add a .cab file as an embedded resource inside a c# .net cf application and then call it with System.Diagnostics.Process.Start ?

     

    Friday, November 28, 2008 1:57 PM

Answers

  • Hi,

     

    Below is a code snippet I have put together that will extract a particular CAB file from the embedded resource (that you have added) and then install it using wceload :-

    NOTE: Firstly, When adding the CAB file, you need to rename the extension to "mycab" otherwise you can set the file to be an embedded resource. Secondly, once the file has been added, you need to right click on it and set the file to be an embedded resource. Thirdly, if you add more resources you would need to change the index used for the mainfestResources string array. As you can see below there is alot of hardcoding such as the location to which the file gets extracted too, the extensions, string array indexs, etc, so these would need to be changed. Also consider the use of using statements to clean up memory and resources.

     

    Code Snippet

    Assembly myAssembly = Assembly.GetExecutingAssembly();

    string[] manifestResources = myAssembly.GetManifestResourceNames();

    Stream myCabFileStream = myAssembly.GetManifestResourceStream(manifestResources[2]);

    if (myCabFileStream is MemoryStream)

    {

    MemoryStream myCabFileMemoryStream = (MemoryStream)myCabFileStream;

    FileStream fs = new FileStream(@"\Temp\" + manifestResources[2].Replace("mycab", "cab"), FileMode.OpenOrCreate);

    fs.Write(myCabFileMemoryStream.GetBuffer(), 0, myCabFileMemoryStream.GetBuffer().Length);

    fs.Close();

    }

    string pathandfilenamewceload = @"\Windows\wceload.exe";

    string pathandfilenamecab = @" \Temp\" + manifestResources[2].Replace("mycab", "cab");

    Process.Start(pathandfilenamewceload, pathandfilenamecab);

     

     

    Hope this helps.

     

    Paul Diston

     

    Friday, November 28, 2008 2:52 PM

All replies

  • Hi,

     

    I think you should be able to do this, you will probably need to read the file from the embedded resource to create a file on the actual device rather than install from the embedded resource. Once you have the file on the device then you could use Process.Start to call WCELoad.exe passing it a parameter of the newly exported cab file.

     

    Paul Diston

     

    Friday, November 28, 2008 2:04 PM
  •  

     

    Thanks for the response,

    Do you have a sample of how to deploy the embedded resource to the device via code.

    Thanks in advance

    Friday, November 28, 2008 2:13 PM
  • Hi,

     

    Below is a code snippet I have put together that will extract a particular CAB file from the embedded resource (that you have added) and then install it using wceload :-

    NOTE: Firstly, When adding the CAB file, you need to rename the extension to "mycab" otherwise you can set the file to be an embedded resource. Secondly, once the file has been added, you need to right click on it and set the file to be an embedded resource. Thirdly, if you add more resources you would need to change the index used for the mainfestResources string array. As you can see below there is alot of hardcoding such as the location to which the file gets extracted too, the extensions, string array indexs, etc, so these would need to be changed. Also consider the use of using statements to clean up memory and resources.

     

    Code Snippet

    Assembly myAssembly = Assembly.GetExecutingAssembly();

    string[] manifestResources = myAssembly.GetManifestResourceNames();

    Stream myCabFileStream = myAssembly.GetManifestResourceStream(manifestResources[2]);

    if (myCabFileStream is MemoryStream)

    {

    MemoryStream myCabFileMemoryStream = (MemoryStream)myCabFileStream;

    FileStream fs = new FileStream(@"\Temp\" + manifestResources[2].Replace("mycab", "cab"), FileMode.OpenOrCreate);

    fs.Write(myCabFileMemoryStream.GetBuffer(), 0, myCabFileMemoryStream.GetBuffer().Length);

    fs.Close();

    }

    string pathandfilenamewceload = @"\Windows\wceload.exe";

    string pathandfilenamecab = @" \Temp\" + manifestResources[2].Replace("mycab", "cab");

    Process.Start(pathandfilenamewceload, pathandfilenamecab);

     

     

    Hope this helps.

     

    Paul Diston

     

    Friday, November 28, 2008 2:52 PM