Can you suggest something for changing the files icons in C#? What I means here is that does C# has any class that we can use to change the icons of files. For example, can I replace notepad file icon with doc file icon in c#?
I know we can extract the icon of a file, but I am looking for applying new icon to a file.
let me try to explain it in details. I am working on a windows app that process files. This app creates a special folder and user can create files and folders into this folders. Now when user creates a files, i want to apply custom icon which shows it as under processing. When processing is done, the file icon will be changed to processing complete. I hope this makes sense now.
Thanks
You will have to write custom shell extension for this. Which are known as "Icon Overlay Handlers". This is the same way by which applications like TortoiseSVN add icons in explorer.
See this MSDN article and this code example
Related
I have a program that can display the contents of a .zip file in a TreeView control. There is one thing I cannot figure out though.
What if we want to display file icons beside our files in the TreeView control? How do you get the file icon for a ZipArchiveEntry. I can't find any info on how to do this and there isn't a method for it on the ZipArchiveEntry class as maybe there should be. Same is true of the .Net File class.
Does anyone know how to get the file icon for a ZipArchiveEntry so I can display it next to the filename in the TreeView control? One would think getting the icon of a file would be a simple thing, but not so much...
You can use this (http://www.brad-smith.info/blog/archives/164) utility.
If you have extension you can use second example.
Only Note that icon of specified file or extension should existed in Windows.
Icon smallIcon = IconTools.GetIconForFile(
#"C:\Windows\System32\notepad.exe",
ShellIconSize.SmallIcon
);
Icon largeIcon = IconTools.GetIconForExtension(".html", ShellIconSize.LargeIcon);
I'm trying to create a card game in C# and for this I have alot of images that I need to load. They're all jpg images and there are about 7000 of them.
I would like to make sure that if you download the game, the images will not be easily accessible, meaning that they should not just be JPG images in a sub folder of the application. So I thought about imbedding them in a DLL file.
But how do I do this? And how do I handle this efficiently? Is there a tecnique to this sort of thing, or is another method preferable?
I would like to make sure that [...] the images will not be easily accessible
First, you should ask yourself why you want to forbid this. If you just want to avoid that someone else manipulates the pictures, you can leave them in a bunch of subfolders as JPGs, just generate checksums for each file and check them at the time the program loads the pictures.
If you want to avoid reuse of the pictures, you can leave them in a bunch of subfolders, but not as JPGs. Encode them with for example with the standard AES algorithm. But beware, that won't prevent anyone else of making screenshots while you application is running, so you should consider if that's really worth the effort.
EDIT: if you want to embed the images because installation gets easier when you have just one big file to deploy instead of 7000 single files, then you may write a helper program for creating resource files programmatically. See this page from Microsoft, especially the part about .resource files, to learn how to utilize the ResourceWriter class for that purpose.
If you have 7000 image, you need a database. Microsoft SQL Server Compact 4.0 is an option. It's small and easy to use.
I'm assuming that this is a windows application
In order to Embed a Image to the assembly
1. Right click the Image file and Select properties
2. In the Properties Pane Set the BuildAction as Embeded resource
So this Image becomes a embeded resource when the application is compiled
Then you can access the Image from the assembly like:
global::[[MyNameSpace]].Properties.Resources.[[ImageName]]
for eg:this.pictureBox1.Image = global::[[MyNameSpace]].Properties.Resources.[[ImageName]]
I have an application in c#.net in which I have embeded the SWF file in SWFObject from COM Object.
Now after installation, the original SWF file also available in the application root directory. So from that place(application root directory) anyone can access that file. But I want to restrict that file from being opened.
axShockwaveFlash1.Movie = Directory.GetCurrentDirectory() + "\\XYZ.swf";
I did something like this.
So how can I restrict that file in application root directory such that only from my application I can access it..??
You can embed the file into a dll or exe file and play it from there. this way it is not (as a seperate file) in the file system at all.
For details see How to embed and access resources by using Visual C#.
You could save the swf file binary data as static bytes in your code and statically load them and convert back to an swf file. The conversion might take a little while but it only occurs once as you open the program.
Edit:
But k3b's answer is better.
Permissions are based on users, not applications, so the short answer is you can't. However, you can build your own application-specific authentication pretty easily. Have your SWF require specific FlashVars to be set in order to move beyond frame 1. People can still decompile your SWF but this will at least stop most people. Another option is to try to store the data within you binary somehow and load the SWF using a byte-array, see this post for one attempt at that.
I've read about icon handlers, but I am unsure how to work with them.
Let's say I have a C# application (or simply a Windows filesystem object such as a .LNK file) and I want to assign it the icon, a PDF File currently is using (or a MS Word file), though the application is not a PDF file itself.
How are icons assigned / where is that association saved? When using tools such as Resource Hacker I can find the icons within application files (of course a PDF file does not have an icon itself). In the registry under HKCR I can find all file types and their respective openers, where are the icons defined? This classifies as multiple questions - I am most interested in how to assign the system's currently assigned filetype icon (e.g. PDF) to my application.
In HKEY_CLASSES_ROOT there will be an entry for the file extension, for example .pdf. The string under this key is the name of a file type, in this case AcroExch.Document. Look up that key, again in HKEY_CLASSES_ROOT, and you will find either a DefaultIcon or CLSID entry. If it's a CLSID you will need to do one more level of indirection - on my system I end up at HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{B801CA65-A1FC-11D0-85AD-444553540000}. Under the DefaultIcon key you will find the full path to the file containing the icon, and the icon number within the file.
You will need to extract the icon from the file and put it into your application. Note that the icon will be trademarked and/or copyrighted by the company that created it - nobody will come after you if it's for your own personal use, but if you release an application using someone else's icon you could find yourself in trouble.
For .LNK files it should be easy. Just right click, "Properties", "Change icon" and in the next dialog "explore". Search the EXE file of e.g. adobe acrobat, the file icon normally sits in the exe file as secondary icon.
For me the path qould be "C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe"
Okay, bad example, the document icon is actually in AcroRd32.dll in the same path, but normally you don't have to search much.
I need help in how to create a custom file extension in my C# app. I created a basic notes management app. Right now I'm saving my notes as .rtf (note1.rtf). I want to be able to create a file extension that only my app understands (like, note.not, maybe)
As a deployment point, you should note that ClickOnce supports file extensions (as long as it isn't in "online only" mode). This makes it a breeze to configure the system to recognise new file extensions.
You can find this in project properties -> Publish -> Options -> File Associations in VS2008. If you don't have VS2008 you can also do it manually, but it isn't fun.
File extensions are an arbitrary choice for your formats, and it's only really dependent on your application registering a certain file extension as a file of a certain type in Windows, upon installation.
Coming up with your own file format usually means you save that format using a format that only your application can parse. It can either be in plain text or binary, and it can even use XML or whatever format, the point is your app should be able to parse it easily.
There are two possible interpretations of your question:
What should be the file format of my documents?
You are saving currently your notes in the RTF format. No matter what file name extension you choose to save them as, any application that understands the RTF format will be able to open your notes, as long as the user knows that it's in RTF and points that app to that file.
If you want to save your documents in a custom file format, so that other applications cannot read them. you need to come up with code that takes the RTF stream produced by the Rich Edit control (I assume that's what you use as editor in your app) and serializes it in a binary stream using your own format.
I personally would not consider this worth the effort...
What is the file name extension of my documents
You are currently saving your documents in RTF format with .rtf file name extension. Other applications are associated with that file extension, so double-clicking on such file in Windows Explorer opens that application instead of your.
If you want to be able to double click your file in Windows Explorer and open your app, you need to change the file name extension you are using AND create the proper association for that extension.
The file extension associations are defined by entries in the registry. You can create these per-machine (in HKLM\Software\Classes) or per-user (in HKCU\Software\Classes), though per-machine is the most common case. For more details about the actual registry entries and links to MSDN documentation and samples, check my answer to this SO question on Vista document icon associations.
I think it's a matter of create the right registry values,
or check this codeproject's article
You can save file with whatever extension you want, just put it in file name when saving file.
I sense that your problem is "How I can save file in something other than RTF?". You'll have to invent your own format, but you actually do not want that. You still can save RTF into file named mynote.not.
I would advise you to keep using format which is readable from other programs. Your users will be thankful once they want to do something with their notes which is not supported by your program.