Opening ms-settings from WPF application - c#

<--------------EDIT:-------------->
I can't use Windows.System
That assembly (and associated classes and namespaces) are for Windows Store apps only.
You cannot use them in a standard C# project.
Reference on MSDN.
Also, the first part of the question has been answered:
If it sounds simple, it is.
Process.Start("ms-settings:SomePage");
So, now the question is, how do you get that to launch inside the WPF Page/Window?
<--------------/EDIT-------------->
I am using Visual Studio 2015 to develop a WPF application. I'd prefer to use C# to launch the ms-settings:whatever page.
Ok, so I'm trying to follow the directions listed HERE on msdn.microsoft, but the assembly they reference "Windows.System" doesn't seem to exist. 0.o
"System.Windows" exists, but it doesn't contain Launcher.LaunchUriAsync...
Below is the snippet of code on that page:
using Windows.System;
...
bool result = await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-webcam"));
So the question is, what am I missing? I'm pretty sure something is flying way over my head and I can't seem to see what is.
Bonus points if you know how to get the ms-settings app to open inside the WPF page, although I'm pretty sure that isn't reasonably feasible.

It seems that Windows treats the ms-settings:... syntax as URI. So, you should be able to open it in the default browser just as you would open any other URI from within C# code:
System.Diagnostics.Process.Start("ms-settings:privacy-webcam");
However, I'm not sure how older versions of Windows (which don't know the ms-settings:... syntax) react to that...

Damn, well I found why I can't use Windows.System
That assembly (and associated classes and namespaces) are for Windows Store apps only.
You cannot use them in a standard C# project.
Reference on MSDN.

Related

Pragmatically Open Database connection

I am working on a project and have scoured the internet for answers on this topic but could not find a single answer, not even an open source solution.
Maybe you guys could help me out.
In visual studio you can open the database connection window by browsing View -> server explorer -> add connection. that is all well and known but what if I wanted to open that same form from code or a certain API. I cant seem to figure it out but there must be some sort of way to access this form pragmatically since its native to Visual Studio.
For all who are unsure what form I'm talking about, here's a snippet:
So my question to you is, how can I , through code, open this window? If there is nothing built into Visual Studio and C#, do you know of any open source software that accomplishes this or will I have to recreate it with a windows form application?
I think you would need to build the form yourself if you need any custom logic etc in which case you could use the ConnectionStringBuilder classes and pass the validated fields from your custom form to the relevant builder class to generate the connection string. Visit here for more information.
Microsoft also has library on nuget that you could use, although it's deprecated so use with caution. The nuget file, which you can download manually, also contains the source code so perhaps you could use this to jump start your own UI component. https://www.nuget.org/packages/DataConnectionDialog

Determine who has a file open using C# - is there a way now?

I need to be able to check who has a file open using C#. I found a few people asked this question before but they were all a long time ago with the latest being in 2012. I was wondering if, in the last 5 years, has Microsoft added this ability to .net or maybe someone came out with a nuget package that is capable.
Here is the latest answer I found
You can use windows internal function NTQuerySystemInformation with undocumented parameter SystemHandleInformation for it. I don't know about c# implementation, but I know delphy code for it, and vb6 code. Check this links, it will help you to make your c# implementation.
Delphi - get what files are opened by an application
https://forum.sysinternals.com/topic14546.html
As far as I know, the standard library still does not have suitable functions for this. There is a popular question about this: https://stackoverflow.com/a/937558/5665527.
Also, if you want to know who opened the file remotely - net file function may be useful (which is accessible via cmd). I believe that there are similar WinAPI functions on MSDN that could be implemented in a similar way.

Altering WatiN.Core dll to work with frames AND iframes

Alright so this may be a total n00b question but I'm using the WatiN 2.1 library with Visual Studio 2013 and I'm trying to automate a mostly javascript-based webpage. I've done this task already using VBA but I wanted to redo it in C#. The webpage has multiple AND elements and some necessary fields are contained in lower levels of each. In VBA, I was able to navigate the page by simple doing something like this:
ie.Document.frames("frameID1").Document.frames("frameID2").Document.getElementByID("target").Click
This line of code would work whether frameID1 or frameID2 were frames or iframes. It didn't seem to matter to VBA. I tried a similar approach in C# using WatiN but it seems like the Frame feature in WatiN only recognizes as frame elements and simply recognizes a element as a simple HTML element.
That being said, I have read the question regarding this found here
but this is where my questoin arises. They say the solution is to alter the code for the AllFramesProcessor method and that fixes it. But how exactly do you access and modify this code? This code is contained in a .dll which I've tried to modify using .NET Reflector. I've export the source code, opened it in Visual Studio, found the code to modify and did so, but when I tried to build a new release, it threw multiple errors. Any suggestions on how to modify this block of code properly and get a version of WatiN that can handle elements?

How to change a website default document programmatically on the fly

Using ASP.NET 4.0, IIS 7.5.
I have a website engine, I have just implemented a way for this to tell if it's being loaded on mobile and instead of loading Controls\MyControl.ascx it loads Mobile\Controls\MyControl.ascx. This works well for my controls and also my MasterPage.Master file.
What I can't figure out however is how I can do the same with Default.aspx. This needs to be done on the fly programatically as I need to be able to check if it's mobile version. I was thinking of doing something on a pre-init event in globals but not sure if that's the best way.
Note: I don't want to use inline code on Default.aspx and just display different content base on my Mobile flag as my scenario goes one step further by basing the file on customer as well and this would mean having one huge Default.aspx for all customers which wouldn't be manageable.
Changing the default document on the fly is not possible in any practical sense.
Writing to the web.config on the fly to load a mobile version of a default page is quite frankly terrible and not an answer to the true context of your issue. I would feel irresponsible as a developer if I even proposed this as an answer to loading a mobile version of a default page.
I was trying to help you solve your problem and not just answer the base question in the title. As we all know, changing the web.config will restart your application and would not serve as a true solution, as you could not do this and achieve any kind of performance.
Here is the BEST alternative (IMHO) to dealing with mobile browsers.
http://51degrees.codeplex.com/
HTH!
For anyone else looking at this I have found a solution but I am not sure I will implement it as I don't like the idea of updating the web.config file at run time. Using the Microsoft.Web.Administration namespace you can update the server.webServer -> defaultDocument section programmatically. Doing this allows you to change the path to default.aspx and it will load based on the variables you set.
This link should provide more information: http://blogs.msdn.com/b/saurabh_singh/archive/2007/11/24/accessing-iis-7-0-features-programmatically-from-configuration-file-s-c.aspx
Also, the Microsoft.Web.Administration dll isn't available directly in VS so you need to add it from %windir%\syswow64\inetsrv (64bit version).

Displaying HTML with Mono on Mac OS X

I gather from this question and others like it, as well as a thorough web search, that libgluezilla is not available for OS X so it is not possible to use the WebBrowser control.
If that is still the case, is there any other way of displaying HTML within a mono application on a Mac?
EDIT: I have tried open-webkit-sharp but get a run time error like 'cannot find file ......\English.ini', which is odd as it exists in the place that is being searched. Following Lex Li's suggestion I tried with MonoMac, but evidently I need to do more than add in some name spaces and a couple of lines of initialisation code to get the program working as it compiles okay but does not actually open a window when run. I think that MonoMac is probably not the way I want to go anyway as it will prevent the code from being cross platform which is why I am going down the mono route.
I have implemented in my application displaying HTML using mono. I use monobjc(http://www.monobjc.net/) and mono 2.8.10. Monobjc 4.0 has webkit dlls in it. You can use it.
There are two ways -
Recommended approach - Using Webkit - Examples available on monobjc site - http://www.monobjc.net/index.php?page=simplewebbrowser. If you download the project you will see the sample code.
Documentation at the site is self explanatory.
2 Not recommended - Using textView -SubClass NSTextView and hook it up with your project. Now add the following code to the Setter of your subclass . I am pasting the code that can be used with monobjc.
NSString str = new NSString(value);
NSData data = str.DataUsingEncoding(NSStringEncoding.NSUnicodeStringEncoding);
var attributedString1 = new NSMutableAttributedString();
NSDictionary dict;
_htmlString = attributedString1.InitWithHTMLDocumentAttributes(data, out dict).CastAs();
TextStorage.SetAttributedString(_htmlString);

Categories