I am trying to apply "PRINT" UserRight to ProtectionDescriptor but its not opening PDF file content.
Trying to find list of UserRights for MIP SDK. I tried "OWNER", it works. But I do not want to give "OWNER" rights. Any help would be great.
var newRights = new List<UserRights>();
foreach (UserSet userset in options.userSet)
{
newRights.Add(new UserRights(new List<string> { userset.Users }, new List<string> { "PRINT" }));
};
ProtectionDescriptor protectionDescriptor = new ProtectionDescriptor(newRights);
You must also include VIEW. VIEW is the base required right to open the content.
Full rights are here: https://learn.microsoft.com/en-us/azure/information-protection/configure-usage-rights
Related
I'm using C# and Xamarin forms to create a phone app that (when a button is pressed) will pull specific html data from a website in and save it into a text file (that the program can read from again later). I started with the tutorial in this video: https://www.youtube.com/watch?v=zvp7wvbyceo if you want to see what I started out with, and here's the code I have so far made using this video https://www.youtube.com/watch?v=wwPx8QJn9Kk, in the the "AboutViewModel.cs" file created in the video:
Image link because this is a new account i guess and i cant embed images or something
Paste of the code itself (but the image gives you a better look at everything):
private Task WebScraper()
{
HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.Load("https://www.flightview.com/airport/DAB-Daytona_Beach-FL/");
foreach (var item in doc.DocumentNode.SelectNodes("//td[#class='c1']"))
{
var itemstring = item;
File.WriteAllText("AirportData.txt", itemstring);
}
return Task.CompletedTask;
}
public ICommand OpenWebCommand { get; }
public ICommand WebScraperCommand { get; }
}
}
The only error i'm getting right now is "Cannot convert 'HtmlAgilityPack.HtmlNode' to 'string'" Which i'm working on fixing but I don't think this is the best solution so anything you have is useful. Thanks :)
HtmlNode is an object, not a simple string. You probably want to use the OuterHtml property, but consult the docs to see if that is the right fit for your use case
string output = string.Empty;
foreach (var item in doc.DocumentNode.SelectNodes("//td[#class='c1']"))
{
output += item.OuterHtml;
}
File.WriteAllText("AirportData.txt", output);
note that you need to specify a path to a writable folder, the root folder of the app is not writable. See https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/data/files?tabs=windows
I am registering installations from my .NET backend server code with multiple templates each. For example:
var installation = new Installation
{
InstallationId = id,
PushChannel = token,
Templates = new Dictionary<string, InstallationTemplate>(),
Tags = new List<string> { "userId:123456" },
Platform = NotificationPlatform.Gcm
};
installation.Templates.Add("template1", new InstallationTemplate { Body = "{\"data\":{\"message\":\"$(message)\"}}"});
installation.Templates.Add("template2", new InstallationTemplate { Body = "{\"data\":{\"message2\":\"$(message)\"}}"});
await _client.CreateOrUpdateInstallationAsync(installation);
How do I target a specific template when sending a notification? All I see in the SDK is the following:
await _client.SendTemplateNotificationAsync(
new Dictionary<string, string>
{
{ "message", "Hello world." }
}, "userId:123456");
The SendTemplateNotificationAsync method does not have any parameters that let me specify which template I am targeting (for example, template2).
Which template will be used? Am I misunderstanding something here?
InstallationTemplate class has Tags property. That's a way to differentiate between templates.
In your case, it looks like you could just skip tagging the entire installation via Installation.Tags property and use something like userId:123456-template tag on specific templates through InstallationTemplate.Tags. Then invoke SendTemplateNotificationAsync the same way you do, but with the template suffix.
I'd like to know if it's possible to set/edit a file extended properties (Explorer: Right-click > Properties > Details) using the Windows API Code Pack.
var shellFile = Microsoft.WindowsAPICodePack.Shell.ShellObject.FromParsingName(filePath);
var artistName = shellFile.Properties.GetProperty(SystemProperties.System.Music.DisplayArtist).ValueAsObject.ToString();
var duration = TimeSpan.FromMilliseconds(Convert.ToDouble(shellFile.Properties.GetProperty(SystemProperties.System.Media.Duration).ValueAsObject) * 0.0001);
I use these few lines to get the properties I want, but I don't know how to edit one of them (the artist name for example).
I know I can use taglib-sharp, but I'll use it only if there is no solution without external code.
Thanks you all for taking the time to help me.
I found a way to edit some properties with ShellPropertyWriter but some properties are read-only.
var shellFile = ShellFile.FromParsingName(filePath);
ShellPropertyWriter w = shellFile.Properties.GetPropertyWriter();
try
{
w.WriteProperty(SystemProperties.System.Author, new string[] { "MyTest", "Test" });
w.WriteProperty(SystemProperties.System.Music.Artist, new string[] { "MyTest", "Test" });
w.WriteProperty(SystemProperties.System.Music.DisplayArtist, "Test");
}
catch (Exception ex)
{
}
w.Close();
In this sample, the 2 first occurences of ShellPropertyWriter.WriteProperty() will do exactly the same, edit the "Contributing artists" field of the file (Explorer: Right-click > Properties > Details). The third call will throw an "Access denied" exception.
Some are editable, others are not. Just need to try.
You can write to the ShellFile directly by setting the value of the properties without ShellPropertyWriter:
var shellFile = ShellFile.FromFilePath(filePath);
shellFile.Properties.System.Author.Value = new string[] { "MyTest", "Test" };
shellFile.Properties.System.Music.Artist.Value = new string[] { "MyTest", "Test" };
shellFile.Properties.System.Music.DisplayArtist.Value = "Test";
Just be aware, that to be able to edit codec-specific fields of a file, it's necessary to have the codec installed on the computer.
Having problems with the documentmanager upload trying to upload PDF's.
The problem happens when creating or deleting folders. The get create/deleted in the correct location but the refresh/processing image stays, crashing the tool from navigating the folder structure. See screen shot:
There is a Javascript error :
this._clientParameters.get_value is not a function
CODE
FileManagerDialogParameters documentManagerParameters = new FileManagerDialogParameters();
documentManagerParameters.ViewPaths = new string[] { uploadPath };
documentManagerParameters.UploadPaths = new string[] { uploadPath };
documentManagerParameters.DeletePaths = new string[] { uploadPath };
documentManagerParameters.SearchPatterns = pattern;
documentManagerParameters.MaxUploadFileSize = maxFileSize;
if (string.IsNullOrEmpty(dialog))
{
// use a default
dialog = "~/modules/uploadcentre/dialogs/default/";
}
documentManagerParameters["ExternalDialogsPath"] = dialog;
DialogDefinition documentManager = new DialogDefinition(typeof(DocumentManagerDialog), documentManagerParameters)
{
ClientCallbackFunction = "DocumentManagerFunction",
Width = Unit.Pixel(694),
Height = Unit.Pixel(440)
};
DialogOpener1.DialogDefinitions.Add("DocumentManager", documentManager);
Telerik.web.ui version 2011.1.519.40
Thanks in advance
Peter
Please, see the following forum thread which discusses the same JS error:
DocumentManager open with DialogOpener javascript error - http://www.telerik.com/community/forums/aspnet-ajax/editor/documentmanager-open-with-dialogopener-javascript-error.aspx
If you need further help, please open a support ticket from www.telerik.com and send a sample fully working project that demonstrates the problem.
Best regards,
Rumen
http://www.telerik.com/community/forums/aspnet-ajax/editor/document-manage-refreshing-image-stays-on.aspx
I'd like to create a small application that can collect system information (Win32_blablabla) using WinRM as opposed to WMI. How can i do that from C#?
The main goal is to use WS-Man (WinRm) as opposed to DCOM (WMI).
I guess the easiest way would be to use WSMAN automation. Reference wsmauto.dll from windwos\system32 in your project:
then, code below should work for you. API description is here: msdn: WinRM C++ API
IWSMan wsman = new WSManClass();
IWSManConnectionOptions options = (IWSManConnectionOptions)wsman.CreateConnectionOptions();
if (options != null)
{
try
{
// options.UserName = ???;
// options.Password = ???;
IWSManSession session = (IWSManSession)wsman.CreateSession("http://<your_server_name>/wsman", 0, options);
if (session != null)
{
try
{
// retrieve the Win32_Service xml representation
var reply = session.Get("http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt", 0);
// parse xml and dump service name and description
var doc = new XmlDocument();
doc.LoadXml(reply);
foreach (var elementName in new string[] { "p:Caption", "p:Description" })
{
var node = doc.GetElementsByTagName(elementName)[0];
if (node != null) Console.WriteLine(node.InnerText);
}
}
finally
{
Marshal.ReleaseComObject(session);
}
}
}
finally
{
Marshal.ReleaseComObject(options);
}
}
hope this helps, regards
I've got an article that describes an easy way to run Powershell through WinRM from .NET at http://getthinktank.com/2015/06/22/naos-winrm-windows-remote-management-through-net/.
The code is in a single file if you want to just copy it and it's also a NuGet package that includes the reference to System.Management.Automation.
It auto manages trusted hosts, can run script blocks, and also send files (which isn't really supported but I created a work around). The returns are always the raw objects from Powershell.
// this is the entrypoint to interact with the system (interfaced for testing).
var machineManager = new MachineManager(
"10.0.0.1",
"Administrator",
MachineManager.ConvertStringToSecureString("xxx"),
true);
// will perform a user initiated reboot.
machineManager.Reboot();
// can run random script blocks WITH parameters.
var fileObjects = machineManager.RunScript(
"{ param($path) ls $path }",
new[] { #"C:\PathToList" });
// can transfer files to the remote server (over WinRM's protocol!).
var localFilePath = #"D:\Temp\BigFileLocal.nupkg";
var fileBytes = File.ReadAllBytes(localFilePath);
var remoteFilePath = #"D:\Temp\BigFileRemote.nupkg";
machineManager.SendFile(remoteFilePath, fileBytes);
Hope this helps, I've been using this for a while with my automated deployments. Please leave comments if you find issues.
I would like to note that this shows an interop error by default in Visual Studio 2010.
c.f. http://blogs.msdn.com/b/mshneer/archive/2009/12/07/interop-type-xxx-cannot-be-embedded-use-the-applicable-interface-instead.aspx
There appear to be two ways to solve this. This first is documented in the article listed above and appears to be the correct way to handle the problem. The pertinent changes for this example is:
WSMan wsManObject = new WSMan();
This is in lieu of IWSMan wsman = new WSManClass(); which will throw the error.
The second resolution is to go to the VS2010—>Solution Explorer—>Solution—>Project—>References and select WSManAutomation. Right click or hit Alt-Enter to access the properties. Change the value of the "Embed Interop Types" property of the wsmauto reference.