c#, How to solve the *.lnk file title? - c#

I want to get title of shortcut, not file name, not description, but title.
how to get it?
I have learn to resolve its target path from here, How to resolve a .lnk in c#
but i don't find any method to get its title.
(source: ggpht.com)
(source: ggpht.com)

It sounds like you might be trying to get the title of the file the link points to, as JRL suggests.
If you're not trying to do that, I'd recommend opening up one of these .lnk files in a hex editor like XVI32. You can probably tell from there whether the Chinese name displayed is embedded in the .lnk file or is somewhere else.
If it's somewhere else, it may be an Extended File Property. There's some source code that may help with retrieving that info: Extended File Properties
If by some chance it is inside the .lnk file, I recommend looking at the Windows Shortcut Specification to get offset information and such on the location of that data.

There is a Desktop.ini hidden file in shortcuts directory, the Desktop.ini file records display strings info of shortcuts.
Desktop.ini file sample:
[LocalizedFileNames]
Windows Update.lnk=#%SystemRoot%\system32\wucltux.dll,-1
Default Programs.lnk=#%SystemRoot%\system32\sud.dll,-1

You can use the property system APIs in latest relase of Code pack:
(all the 670+ properties in the system are accesible using simple property accessors)
http://code.msdn.microsoft.com/WindowsAPICodePack
I know your current need is only limited title of lnk files. Using the above library, the sample code might look like:
ShellLink myLink = ShellObject.FromParsingName("c:\somepath\myLink.lnk");
string title = myLink.Properties.System.Title.Value;
// This is what its pointing to...
string target = myLink.Properties.System.TargetParsingPath.Value;

Please define "title". The only attributes that sound relevent are the shortcut's file name, the target's file name, and the .lnk file's description data.

Assuming you mean the title of the file the link points to, not the link itself, and that you are talking about Windows, then it's done via a feature in NTFS, alternative streams. You can access those streams using code in this article.

Looking around on creating shortcuts, looks like there's a lot of jumping through hoops with scripting objects. But am I missing something? If you have a path to the shortcut, the name should be exactly what you find in the path, not some attribute you have to look up.
Dim f As FileInfo = New FileInfo("C:\Name of shortcut.lnk")
Dim title As String = f.Name.Replace(".lnk", String.Empty)

Related

Differences between "Path" and "Directory" classes and means

I don't understand the difference between path and directory. Could someone explain to me with examples?
I'm trying to understand how to different classes of system.IO namespace works. But in logicaly I didn't get the mean what is "Path" , what is "Directory". Aren't they both the same thing? Why they divided these 2 thing into two different classes?
Directory is more of a confirmation or assessment of. For example. Does a directory exist providing a string representing the path you are interested in. Create a directory, again, provided a string representing the path.
var myStrPath = #"C:\Users\Public\SomePath\";
if( ! Directory.Exists( myStrPath ))
Directory.Create( myStrPath );
You can also enumerate a given folder looking for more, or cycling through them.
var df = Directory.GetDirectories(#"C:\");
foreach (var oneFolder in df)
MessageBox.Show(oneFolder.ToString());
But you can also use Directory based on RELATIVE Path. For example, where your program is running from, you could do
if( Directory.Exists( "someSubFolderFromWhereRunning" ))
and not worry about fully qualified path.
Path allows you to get or manipulate path/file information, such as a relative path above and you want to know its FULL path even though you dont know where your program is running from. This might be good to look for an expected startup check file in the relative directory the app is running from, or writing files out to same working folder.
You can also get the list of bad characters that are not allowed in a path so you can validate against them in some string.
For each of them, take a look at the "." reference after you do something like
var what = System.IO.Directory. [and look at the intellisense]
var what2 = System.IO.Path. [intellisense]
And look at the context. It should make more sense to you seeing it with better context.
A Directory is a disk file that contains reference information to other files. or in simple words, it is a folder.
A Path is just a string wrapped in a Path Class in C# which facilitates us with many different conventions depending on the operation system.

How to get the name and the path of the picture I've just inserted to document (MS Word) by C#?

I have a document and I insert a picture (name koala.jpg from C:\Data) to this document. I want to check that I inserted the exactly picture (koala.jpg from C:\Data not another picture). So I hope I will get the name and the path of this picture that was inserted. I found a lot on the Internet but I don't have any good idea to fix this problem. I found out LinkFormat.SourceFullName in Microsoft.Office.Interop.Word but I don't know how to use it. I think LinkFormat.SourceFullName is used for Inser Picture type "Link to file". But my picture is inserted at default "Insert" (not Insert Link to file).
I hope you can give me the idea to fix my problem.
Microsoft.Office.Interop.Word.Application oWord = (Microsoft.Office.Interop.Word.Application)w;
_activeDoc = oWord.ActiveDocument;
MessageBox.Show(_activeDoc.InlineShapes[1].LinkFormat.SourceFullName.ToString());//is error
Word does not store this information in the document. It does store the name of the original file in the Word Open XML, but not the original file path. And the file name is not exposed to the object model ("interop"), it can only be extracted from the Word Open XML (which can be read from the "interop", via the Range.WordOpenXML property.
If you need to trace the entire file path of an image then your application needs to manage the interface used to insert it. Either "roll your own" dialog box or leverage Word's built-in dialog box.
Both are possible, but the latter requires PInvoke when using C# as the dialog box arguments are "late-bound" into the Word object model and thus not accessible via the object model for C#.
For an example on how to use Word's built-in dialog boxes in C#, see this Stack Overflow answer. A list of built-in dialog boxes with their arguments can be found at https://learn.microsoft.com/en-us/office/vba/word/concepts/customizing-word/built-in-dialog-box-argument-lists-word. The built-in dialog box argument to return the file path for the picture the user selected is Name.

Correct filepath to read from file

I want to read from a file. But i do not how to alter to the correct filepath.
I just want to read from a file called Level.txt. If I do; string path = "Level.txt".
The program tries to search it from; C:\...\ProjIV\ProjIV\bin\x86\debug\Level.txt.
When I want the damn thing in: C:\...\ProjIV\ProjIV\ProjIVContent\Level.txt.
Skip the second question. As someone else said, one question at the time. Also; solved.
If you just provide a path like that, your program will search in the running (working) directory that it is executing in. You can provide an explicit path:
C:\<whatever you need here>\ProjIV\ProjIV\ProjIVContent\Level.txt
Or a relative path:
..\..\..\..\ProjIVContent\Level.txt
That's pretty ugly though, I'd stick with the first one. Or move Level.txt into your working directory.

How to do a find in a Resource file?

I am wondering say I have this string "Hi my name is chobo2" and I want to find all the files that have this string. Normally I would do ctrl + f in VS 2010 and do a find.
How do I find this string if it is in a resource file? Right now I have a string in a solution that has many projects. I know the project has at least one resource file but I cannot find the string I am looking for. I might have missed it as the file seems to have many string in it.
Is there any easy way to locate this string value in the resource file? This way I can find the "resource name" and thus find where the string is used in the project.
Edit
Just a side note
I opened up the resource file and tried to do a ctrl + f on it(search by current document) but it only searches on the "name" column not the "value" column
I think this will explain all you need to find the string. ****Cheers**** to vs2010
In resharper it is very easy -> find usages (or something similar)
But you can use Ctrl + Shift + F (select entire solution) in file type section type *.* or *.resx and click find (on panel below all occurrence should appear) double click should drive you directly to resx file (Xml)
Press Ctrl+Shift+F and select Entire solution. Then use F8 for navigation on found items. In addition, for finding related resource files, goto Tools->Option->Project and Solution and check Track Active Item to true.

MacVIM Syntax file for CS

I am using MacVim to convert cs files to HTML. The convert function works fine. However, I don't like the default syntax highlighting for cs.
I understand that the cs syntax file in at /Applications/Vim/MacVim.app/Contents/Resources/vim/runtime/syntax/cs.vim, Maintainer by Anduin Withers. Not sure if there is any other way to substitute this one with a better syntax highlight file or update it with a a newer version?
You are probably looking for colorscheme files. Syntax files define which part of text (source code) is what, for example it identifies keywords, function names and variables and so on. Color scheme defines what color should each component get.
To change color try
:colo <name of colorscheme>
To cycle through existing schemes use tab:
:colo <TAB>
You can get new colorschemes (choose the ones you like and save as plain ascii files) and store them in your $HOME/.vim/colors directory which is searched by vim before the standard one that you mentioned above.

Categories