How to add shortcut link in "Quick Access" in Windows 10 through code? - windows-10

I want to add shortcut link of one of the folder location to "Quick Access" in windows 10.
In the case of Windows 7 & Windows 8, I used to put my shortcut link in the folder "C:\Users\user_name\Links" & it showed me shortcut in favorites at left side. So I want to do same thing for Windows 10.
I directly copy shortcut & pasted into the location of Quick Access. But still it's not showing in left panel of Quick Access.
As i know there are two option in Quick Access : 1. Frequent Folders & 2. Frequent Files.
So at what location do I need to put that shortcut link so it will appear in Quick Access section in left panel ?
And also I wanted to ask, how "OneDrive" link they have added in left panel in Windows 10 ? So is there any registry entry or any specific location ?

You can do it via this powershell script:
$o = new-object -com shell.application
$o.Namespace('c:\Folder').Self.InvokeVerb("pintohome")

I didn't found proper solution.
But I applied workaround for my problem.
I created folder at Quick Access location (\Links). And using mkilink cmd I changed the symbolic link of it to target folder. I used mklink using cmd prompt in C# code using Process.

I am using following code to create folder shortcut at c:\users\user_name\links and it is working fine in windows 7 & 8 but can't see it under windows 10 quick access link in windows explorer.
string sLinkFileName = "c:\users\user_name\links\\" + DefineString.AppName + ".lnk";
FileInfo objfiLinkFile = new FileInfo(sLinkFileName);
if (objfiLinkFile.Exists)
{
try
{
objfiLinkFile.Delete();
}
catch (Exception ex)
{
Logger.Log(LoggingLevel.Info, MethodBase.GetCurrentMethod().Name, string.Empty, ex);
}
}
//Place a shortcut to the file in the special folder
objfiLinkFile.Refresh();
if (objfiLinkFile.Exists)
{
Logger.Log(LoggingLevel.Info, MethodBase.GetCurrentMethod().Name, "Old link file still exists.");
}
// Create a shortcut in the special folder for the file
// Making use of the Windows Scripting Host
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
IWshRuntimeLibrary.IWshShortcut link = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(objfiLinkFile.FullName);
link.TargetPath = Utils.msApplicationRootPath;
link.WindowStyle = 1;
link.Description = string.Format(DefineString.m00025, DefineString.AppName);
link.IconLocation = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\RootFolder.ico";
link.Save();
I also tried to call mklink as you mentioned; but it didn't work. Unfortunately we don't have any direct control over user desktop. mklink command requires admin privileges? Which mklink command you used to fix the issue. Your help will be greatly appreciated.
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = string.Format(#"/C mklink {0} {1}", sLinkFileName, Utils.msApplicationRootPath);
process.StartInfo = startInfo;
process.Start();

Related

Sharepoint 2013 custom standard UI icons

i'm currently building up a design-solution-feature for SP13. it deploys master pages, layouts, css files etc.
my question is: is there actually any way to implement custom standard UI icons? e.g.: for the ribbonrow or settings icon on the top right corner?
it would be perfect if i could just overwrite the generated themedpng with a custom one (same dimensions of course) via code (event receiver).
Here are two ways to do it, but none of them is the perfect solution.
1- Backup "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\IMAGES\spcommon.png" and replace it with your own file.
This is not recommended because you should not touch SharePoint files.
It could be overwritten when installing a SharePoint update.
But it is an easy solution which is used sometimes in the real world.
2- You can use jquery (or javascript) to replace all references to "/_layouts/15/images/spcommon.png" by your own image once the page is loaded. You can deploy your image on your site.
Problem is the out of the box image will be displayed first and then replaced by your image. So there will be a very short time were the old image will be displayed.
this script included in the masterpage did it for me:
var CustomIcons = function () {
var site_url;
if (_spPageContextInfo.siteServerRelativeUrl === "/") {
site_url = "";
} else {
site_url = _spPageContextInfo.siteServerRelativeUrl;
}
var commom_img_url = site_url + '/_layouts/15/images/spcommon-custom.png';
var commom_img_url2 = site_url + '/_layouts/15/images/spcommon-custom2.png';
var help_img_url = site_url + '/_layouts/15/images/help.png';
var settings_img_url = site_url + '/_layouts/15/images/settings.png';
$('#siteactiontd').find('img:first').attr('src', settings_img_url);
$('#ms-help').find('img:first').attr('src', help_img_url);
$('#ctl00_SyncPromotedAction').find('img:first').attr('src', commom_img_url);
$('#ctl00_fullscreenmodeBtn').find('img:first').attr('src', commom_img_url);
$('a[_action="edit"]').find('img:first').attr('src', commom_img_url);
$('a[_action="save"]').find('img:first').attr('src', commom_img_url2);
}

Cut, Copy and Paste for Node-WebKit app doesn't work in OSX

I have created a Node-Webkit app for chat. For windows and linux, cut, copy and paste commands are working fine. But the same is not working in OSX.
Please help me solving this issue.
Thanks in advance.
You need to implement the native OSX edit menu for copy and paste to work properly. This should do the trick:
// initialize window menu
var win = gui.Window.get(),
nativeMenuBar = new gui.Menu({
type: "menubar"
});
// check operating system for the menu
if (process.platform === "darwin") {
nativeMenuBar.createMacBuiltin("Your App Name");
}
// actually assign menu to window
win.menu = nativeMenuBar;
Further reading on menus in Node-Webkit.

How to get local file system path in azure websites

I have a file hosted on the disk along with my website that I want to read .Not sure how do I access the file when I use System.Environment.CurrentDirectory it point to a D drive location .Can someone please tell me how can I get to my file stored at the root of where my site is hosted.
Thanks
There is an environment variable called HOME in your website's environment that will get you part way there.
You can access it using razor syntax or in code (C#). For example, suppose you have a file called data.txt that is at the root of your site with the default document and the rest of your files. You could get it's full path like this.
#{ var dataFileName = Environment.GetEnvironmentVariable("HOME").ToString() + "\\site\\wwwroot\\data.txt"; }
You can find this out on your own using the Site Control Management/"Kudu". For example, if your website is contoso.azurewebsites.net, then simply navigate to contoso.scm.azurewebsites.net. In here you can learn all about the file system and environment variables available to your website.
For testability, I use below code.
string path = "";
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HOME")))
path = Environment.GetEnvironmentVariable("HOME") + "\\site\\wwwroot\\bin";
else
path = ".";
path += "\\Resources\\myfile.json";
In above example, I added myfile.json file to Resources folder in a project with Content and Copy if newer property setting.
This works for me in both localhost and azure:
Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "file_at_root.txt");
System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath is the full local path to your site's root.
I'm currently using AppDomain.CurrentDomain.BaseDirectory (.NET Core project). It returns "D:\home\site\wwwroot\" in Azure and the application root in local so the only difference is adding "bin\\" when it is Azure. I am searching the entire directory tree, just in case, but it can be trimmed.
It's something like:
private static string GetDriverPath(ILogger logger, string fileName)
{
var path = AppDomain.CurrentDomain.BaseDirectory;
if (File.Exists(Path.Combine(path, fileName)))
{
return path;
}
string[] paths= Directory.GetFiles(path, fileName, SearchOption.AllDirectories);
if (paths.Any())
{
return Path.GetDirectoryName(paths.First());
}
throw new FileNotFoundException($"{fileName} was not found in {path}.", fileName);
}
I'm new answering questions and this is an old one but I hope it helps someone.
You can do it using the below code.
string fullFilePath = Environment.GetEnvironmentVariable("HOME") != null
? Environment.GetEnvironmentVariable("HOME") + #"\site\wwwroot\test.txt" //It will give the file directory path post azure deployment
: Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())) + #"\test.txt";//It will give the file directory path in dev environment.

Open web page in After Effects with ExtendScript

This may be a simple one but I can't figure it out. How can I open a web page in the main browser from extendscript as I would do with window.open() in Javascript?
I am targeting After Effects and would like it to work on both OS X and Windows.
In After Effects you can simply do it using the system object, as Dirk mentioned. However you need several things for that:
checking that the script can access the network:
if (app.preferences.getPrefAsLong("Main Pref Section", "Pref_SCRIPTING_FILE_NETWORK_SECURITY") != 1)
{
alert("Please tick the \"Allow Scripts to Write Files and Access Network\" checkbox if Preferences > General");
// Then open Preferences > General to let people tick the checkbox
app.executeCommand(2359);
// Here you should check again if they ticked it, and choose to continue or stop ...
}
checking of the OS:
var os = system.osName;
if (!os.length)
{
// I never remember which one is available, but I think $.os always is, you'll have to check
os = $.os;
}
app_os = ( os.indexOf("Win") != -1 ) ? "Win" : "Mac"
os-dependent system calls:
var url = "http://aescripts.com";
if ( app_os == "Win" )
{
system.callSystem("explorer " + url);
}
else
{
system.callSystem("open " + url);
}
Provided you have access to CSInterface.js:
cep.util.openURLInDefaultBrowser("http://www.google.com")
One application independent way is to write an operating system's representation of the URL into a file, then execute() the file.
On the Mac that would be a .webloc file. The underlying format is "plist binary", if you prefer to generate xml, create a sample webloc by drag&drop from the browser address and convert it:
plutil -convert xml1 ~/Desktop/sample.webloc
To invoke that webloc, run the ExtendScript
File("~/Desktop/sample.webloc").execute()
You can do anything on your local computer - commandline and anything else in a VBS file, and you can launch a vbs file from javascript like this:
function RunScriptVBS(whatscriptname){
app.doScript(File(whatscriptname), ScriptLanguage.VISUAL_BASIC);
}
Here is your vbs script:
Dim objShell
Set objShell = CreateObject("WScript.shell")
objShell.Run ("http://www.somewhere.com")
set objShell = nothing
The scope of the question apparently has been refined to After Effects (AE), so I add another answer specific to that application.
On my Machine AE CS6 does not produce an object model file for display by the ExtendScript Toolkit. Please retry it yourself, the object model viewer is in the help menu of ESTK.
Anyway, the ESTK data browser does works. If you target AE, you'll see a couple of objects and classes. Eventually check some more menu items in the databrowser panel flyout menu. I had a deeper look at the app object itself (no openUrl() there) and also found a "system" object. Expand that and you see several interesting methods.
The following script opens a URL on the Mac. I have not tried Windows, maybe it is even the same.
system.callSystem("open http://www.google.com")
As this is the first time I launched AfterEffects, I might have missed better ways.

How do I open a file with my application?

Ok, you know how in programs like Microsoft Excel, or Adobe Acrobat Reader you can click on a file in explorer and it will open with the associated program. That's what I want my application to do. Now, I know how to set up the file associations in Windows so that it knows the default program for each extension. My question is how do I get my application to open the file when I double click the file.
I've searched the web using google, I've searched the msdn site, and I've searched several forums including this one but I haven't found anything that explains how to accomplish this. I'm guessing it has something to do with the parameters of the main method but that's just a guess.
If someone can point me in the right direction I can take it from there. Thanks in advance for your help.
Shane
Setting up the associations in windows will send the filename to your application on the command line.
You need to read the event args in your applications main function in order to read the file path and be able to open it in your application.
See this and this to see how to access the command line arguments in your main method.
static void Main(string[] args)
{
System.Console.WriteLine("Number of command line parameters = {0}", args.Length);
foreach (string s in args)
{
System.Console.WriteLine(s);
}
}
When you open the file, with associations set as you described, your application will be started with the first argument containing the filepath to your file.
You can try this out in a simple way by printing out the args from your main method, after you open your application by clicking on the associated file. The 0th element should be the path to your file.
Now, if you successfully reached this point, the all you need to do now is read the contents of the given file. I'm sure you'll find more than plenty of resources here on how to do that.
I guess this is what you are looking for:
FileInfo fi = new FileInfo(sfd.FileName); //the file you clicked or saved just point
//to the right file location to determine
//full filename with location info
// opening file
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = #fi.FullName;
startInfo.WindowStyle = ProcessWindowStyle.Normal;
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
You will need to create registry-keys for your file-extension. This page describes well, which keys you'll need to set (see «3. How do I create file associations?»).

Resources