locked
extract files after embedding them in C# project? RRS feed

Answers

  • Path.Combine lets you combine a path and a filename:

    string mypath = "c:\mypath";
    FileStream fs = new FileStream(Path.Combine(mypath, filename), FileMode.Create)
    
    Thursday, July 29, 2010 3:32 PM
  • Yes. This retrieves all the files you marked as embedded resource. But all resources names are prefixed with the default namespace.

    Thursday, July 29, 2010 4:01 PM
  • No. The default namespace will be in front of the filenames in the array. If you want to save them with their original name, you'll need to remove it.
    Thursday, July 29, 2010 4:20 PM

All replies

  • Can please explain what do you want to do ?


    Regards Puboo My Personla blog : http://thurupathan.spaces.live.com
    My technical Stuff : http://wondersheet.wordpress.com
    Thursday, July 29, 2010 4:52 AM
  • So what I am trying to do is create a installer.

    The following are the steps I need to do. 

    I have created the forms listed below but need to package all files in a directory into this installer. 

    1) create welcome form

    2) select install directory form

    3) select location form(contains 3 radiobuttons

    4) select benchnumber form(textbox)

    5) copy files and preserve directory form(but I won't have access to a server so I need to package the files into this installer)

    6) set up database form(progressbar)

    7) execute exe 

    8) execute one.exe if first radio button selected and another installer if second radiobutton selected on this form

    9) done form(create shortcut but only pass benchnumber text as argument to shortcut after targetpath if a certain radiobutton is selected in location (form 3)) 

    Thursday, July 29, 2010 5:06 AM
  • hi, if i understood correctly: you want to create setup (msi) with your resources. if yes, please read

    http://www.codeproject.com/KB/dotnet/Win_App_Setup_Project.aspx

    http://www.dreamincode.net/forums/topic/58021-deploying-a-c%23-application-visual-studio-setup-project/

    it's very easy to add your resources. it is not necessary to create your own forms. custom forms are in setup project


    BR, Karol
    Thursday, July 29, 2010 5:53 AM
  • is there any way to go back to one of the existing forms under the user interface? Such as the installation folder form which already exists from a custom form which contains a back button.
    Thursday, July 29, 2010 2:11 PM
  • I found the following code but where does it create the file?

     

    private void SaveAllResources()

            {

                Assembly A = Assembly.GetExecutingAssembly();

                string[] names = A.GetManifestResourceNames();

     

                foreach (string filename in names)

                {

                    Stream S = A.GetManifestResourceStream(filename);

                    byte[] rawFile = new byte[S.Length];

     

                    //Read the data from the assembly

                    S.Read(rawFile, 0, (int)S.Length);

     

                    //Save the data to the hard drive

                    using (FileStream fs = new FileStream(filename, FileMode.Create))

                    {

                        fs.Write(rawFile, 0, (int)S.Length);

                    }

                }

            }

    Thursday, July 29, 2010 3:18 PM
  • Since resource names don't contain a path, they're written to the current directory.

    Thursday, July 29, 2010 3:24 PM
  • How would I add a path to it? would i put a string ""? 

    Thanks,

    Aniket

    Thursday, July 29, 2010 3:25 PM
  • Path.Combine lets you combine a path and a filename:

    string mypath = "c:\mypath";
    FileStream fs = new FileStream(Path.Combine(mypath, filename), FileMode.Create)
    
    Thursday, July 29, 2010 3:32 PM
  • When I embbedd a dll into an exe shouldn't i be able to extract it with the code above ?
    Thursday, July 29, 2010 3:42 PM
  • Yes. This retrieves all the files you marked as embedded resource. But all resources names are prefixed with the default namespace.

    Thursday, July 29, 2010 4:01 PM
  • So I would need to add default name space in front of every string in this array?

     

     string[] names = A.GetManifestResourceNames();

    Thursday, July 29, 2010 4:10 PM
  • No. The default namespace will be in front of the filenames in the array. If you want to save them with their original name, you'll need to remove it.
    Thursday, July 29, 2010 4:20 PM
  • I have multiple forms can I embed files into each form and access them? Because right now when i run debugger, it is gathering resources for all forms or can I just delete all the res files which are created with forums without affecting my project?
    Thursday, July 29, 2010 4:26 PM
  • thanks, it works. Just forgot to call it in. 
    Thursday, July 29, 2010 4:48 PM
  • Is there a way I can do this on multiple resource files? 
    Thursday, July 29, 2010 6:07 PM