All, the question is a basic one. I have been loading all .png icon that I use in a complex UI as a resource. This means that the 'Resource' folder contains approx. 100-150 small .pngs. This works but should I be doing this and if not what should I be doing?
Thanks for your time.
well basically, if you think the images will change then store them outside a resource file. If they're going to be static over the lifetime of the application (or its version) then a resource file is fine
Related
I am currently creating a console applications that only accepts some commands defined by me. The thing is I'm storing a lot of error and notification messages on a static class I created called Messages and then just calling them like Messages.ErrorMessage.... ErrorMessage is just a static string that contains w/e I want printed on the console.
What I wanted to ask is if that's a good way of implementing such behavior or should I instead change where I'm keeping all of this Messages?
Thanks for your help!
I guess for your need you can use Resource file instead of static class.
as documented on official site
Visual C# applications often include data that is not source code.
Such data is referred to as a project resource and it can include
binary data, text files, audio or video files, string tables, icons,
images, XML files, or any other type of data that your application
requires. Project resource data is stored in XML format in the .resx
file (named Resources.resx by default) which can be opened in Solution
Explorer.
For more information :-
http://msdn.microsoft.com/en-us/library/7k989cfy(v=VS.90).aspx
As suggested by others, storing them in resource files is the recommended way to deal with such resources, particularly if you'll need to deal with internationalization. then you can load a different resource file from a satellite assembly at run time with the correct information.
You will notice a slight performance hit as the strings will be looked up in a resource dictionary, but usually that is negligible.
<Application.Resources>
<BitmapImage x:Key="MyImageSource" UriSource="C:\Users\nwrobinson\Pictures\skyskanlogo.jpg" />
</Application.Resources>
hello,
im having an issue with the way C# handles resources, i understand that the above code is a reference to a picture, but i assumed that when the program compiled, it would include the picture for when it runs on other computers. instead, it just crashes when the resource is not present in that location. this makes no sense to me, there has to be a way to include the picture in the program so it will run right?
the way it was explained to me, the application always has to have a photo to reference, so does that mean every time i give someone the application i have to send them the photo as well, or is there a way to have the photo wrapped into the application.
this is my first WPF so im not 100% sure what going on all the time, it might have just been something that was overlooked.
thanks for the help
What you want to do is to add the picture to your project and set its Build Action to Resource. Then you can change your UriSource to something like
UriSource="pack://application:,,,/YourProjectAssembly;component/DirectoryName/FolderName/ImageName"
When you look at the properties for the image in Visual Studio, you can select a Build Action. This can be one of many options, including copying the image to the build folder, embedding it as a resource, and others.
Depending on how you include the image in your project, you will need to use the Pack URI syntax to specify where the image can be found. It is not straightforward, but there are enough examples here (http://msdn.microsoft.com/en-us/library/aa970069(v=vs.110).aspx) for when the resources are embedded etc. that you should be able figure it out. It typically involves specifying the assembly in which the resource is located and a relative path, with a very specific assortment of punctuation interspersed.
I have a WPF program which deals with images on a canvas.
I am at the stage where I am trying to use serialization to be able to save the contents of my program and reload it at a later stage.
So At the moment when I am inserting any images into a control I am using absolute path values, I understand that this would be a bad idea for a program where I am wanting to save the state of the program and reload it at a later time.
So what is the best course of action to take in this situation.
Do I create a folder inside my WPF project for example called Images and then do I copy all Images I use in my program to this folder and then point the path to this?
Or am I completely on the wrong lines here?
If you are serializing the state data of your application, you would usually create a folder in one or more of the so-called system special folders, which you can get by a call to Environment.GetFolderPath.
You may for example store data with application scope (same for all users) in a folder below the special folder specified by the SpecialFolder.CommonApplicationData enum (which is C:\ProgramData on Windows 7 systems).
Data that is specific for the current roaming user (who works on multiple computers on a network), would be stored in a folder below SpecialFolder.ApplicationData. There is also SpecialFolder.LocalApplicationData for the non-roaming user.
You may take a look at the Environment.SpecialFolder enumeration to get an overview.
From my own experience, create a folder and save the images there. It will just make your life easier in the long run, and it makes it easy to see where the resources of the application are.
I am developing a Kinect application in C# using WPF under Visual Studio 2010 Express. The application requires a single Image control to switch between about 700 different source images, amounting to about 260 MB altogether. I did not think it would be too much, but when I make those 700 images resource files, when I try to publish (or just run) the application, the build fails, apparently due to lack of memory (I have 8 GB of RAM). It's the same for Content files. The application works just fine as long as I start it from code and read the images from a specified folder, though.
So I have been thinking about Site of Origin files. I have set Build Action to None and Copy to Output Directory to Copy Always for all the image files and rebuilt the project. However the image files don't appear anywhere in the published application. I have tried setting the output path to different folders, but nothing seems to work.
So my question is, are Site of Origin files the right way to go, and if so, what am I doing wrong? Also, once I do manage to have them published along with the rest of the application, how exactly would I access them from code? (Yes, I know that is reversing the actual process – I just mean in principle. I haven't been able to find much on this – basically just this, but it's for Visual Basic. I'd like to access them from C#, not XAML.)
Or, is there some other way to do this? Have I been doing something wrong when trying to use resource files initially?
Thanks in advance!
Hello guys I think the question i asked in the previous post is unclear OK fine. i am explaining in brief.
for example.
I have a form where i have placed one textbox and command button.
I have fired a event when i click the button the text under the textbox change to "hello" ok fine.
what is my problem is..
the application is created and I published ok.
After some week I thought I want to update my application. where in the place of "hello" I want "hi". I know that we can compile the whole project and publish it.
but I don't want my whole application to be updated.
for example.
What antivirus company do they have a definition file where they only update the definition file not the whole application. after the update it applies to whole application.
I want my application also to do same process like antivirus company do.
You should read that "Hello" from a content file (XML). Then you can just push out the new file.
Use a configuration file. You can add an application.config (or if you're developing a web app, web.config) file to your primary project. Within this configuration file, you can define AppSettings (which are built-in, usually simple and atomic string or number fields that the application will need), ConnectionStrings (which specifically provide information applications will need to connect to a database), or custom configuration sections (used for more complex, related sets of data that are loaded into custom classes you define, such as a basic company profile). Within your code, you access AppSettings by using the static ConfigurationManager.Appsettings[] collection; you tell it the name of the setting you defined in the file, and it returns the value (or null, if it can't find the setting you defined).
Related, but different, is the use of Resource files. Resource files usually contain a dictionary of location-specific data used by the UI, such as text strings, icons and images. Actual resources can be compiled into one big file, or resource files can be a list of paths and filenames to the actual resources. You can use resource files to create different "skins" for your application to be used by different companies by referencing images to use for UI elements, or to translate labels and other text on your application's UI. Resource files are accessed through a ResourceManager; you tell it where the resource file is, and it will load the information into a similar "dictionary"; you then tell it the name of the resource and you get the resource back.
For your specific question, I'll answer the same thing as Henk. But, I think that your real question is "How I do create patch in .NET".
You can check this link:
How can I patch .NET assemblies?
You could design your application to use plugins. This way you only have to update a plugin and not the whole application.
if you want to create a patch for asp.net application , first of all , you have to deploy your project with Web Deployment Project.
then choose Create a separate assembly for each page and control output in output assemblies tab and re-build your solution .
the result of deployment is bunch of DLL which mapped to each page or control.
Now if you changed one page's data (in code behind) , you need to deploy your project again but in this case you can just upload the changed dll file.