1

I have folder inside my project called "Multimedia". I want to use C# code to update this folder with images that my users selected. Now i have tried this:

     string path = AppDomain.CurrentDomain.BaseDirectory.Substring(0, AppDomain.CurrentDomain.BaseDirectory.Length - 10);
            string name = Path.GetFileName(MyDialog.FileName);
            File.Copy(MyDialog.FileName, path + "\\Multimedia\\" + name);
            LogoMovie.Source = new BitmapImage(new Uri(@"/QuillaCine;component/Multimedia/" + name, UriKind.RelativeOrAbsolute));

And this copies the image into the folder, but in the Solution Explorer, the folder remains empty. I need that the images appear in the Solution Explorer with Built-In acction set to "Resources".

Any help would be great

2 Answers 2

2

New files are not added to the Solution Explorer. Click the SHOW HIDDEN FILES button in the Solution Explorer toolbar, and then you will see these new files. You will then need to include them in the project (right-click > include files), and then set them as Resource in the properties.

To automate all of this, you would need to create a VSIX Package/extension for Visual Studio, or automatically edit the .csproj file. Can get messy.

Sign up to request clarification or add additional context in comments.

3 Comments

just for curiosity, how exactly would you automatically edit the .csproj file?
You can load it as an XML file and add the following chunk of code to the main node. <ItemGroup> <None Include="Resources\Images.png" /> </ItemGroup>
Do note that this is only for the sake of development, when END-USERS select their own images, simply copy them to Application directory, and OnStartup, load them into some ResourceDictionary
2

1. Adding resources with the drag and drop

You can simply open two windows. One containing your visual studio instance and the other the parent of the folder you want to get the file from. Make sure to be in the solution view in your VS.

enter image description here

enter image description here

Simply drag and drop from folder to VS. That is as simple as it gets. or you can follow Gants answer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.