How can Windows file and folder shortcuts be created via C#.NET code?

喜欢而已 提交于 2019-12-12 17:06:56

问题


I'm building a repository folder and file structure with many dependencies in version control using .NET for our data warehouse. Currently I have code to create dummy files and folders with C# code (see below). However, there are objects being shared. So I'd like to create shortcuts to Windows files and shortcuts to Windows folders as well as files. What would the code look like in C# to accomplish this?

Create Folder via C#.NET code:

string activeDir = @"C:\Source\EDW\dw-objects\trunk\table-objects";
string objectName = reader[0].ToString();
string newPath = System.IO.Path.Combine(activeDir, objectName);
System.IO.Directory.CreateDirectory(newPath);

Code varies depending on files based on format


回答1:


Please use the ShellClass to create shortcuts also you will need to get the special directory from desktop using Environment.SpecialFolder.DesktopDirectory

A very good example showing step by step can be found here http://www.codeproject.com/Articles/146757/Add-Remove-Startup-Folder-Shortcut-to-Your-App




回答2:


Have a look at This Article it shows you how to manipulate NTFS Juncture points using c#. Because you will want to access the folders you need to have juncture points instead of shrotcuts since one is followed by machine processing and one isn't.



来源:https://stackoverflow.com/questions/11513681/how-can-windows-file-and-folder-shortcuts-be-created-via-c-net-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!