On this blog I regularly publish articles with tips and tricks for the programming language C# .Net.
C# is a modern, object-oriented programming language, which fully ultilizes the possibilites of the .Net framework. I also write about app programming for Android via C#, as well as PHP and Matlab. The difficulty of this blog is supposed to be variable, I hope for beginners and experts there is always something to look for.
If you have questions or suggestions, I am happy about your emails.

Monday, January 26, 2015

In this post I want to show, how one can change the password of a Windows user using C#.
For this there are multiple possibilities, here we use the class PrincipalContext.
Using this, but also the other methods, in Windows 8 it is important that the type of user account is set to local (can be changed), and not to Windows account.
In the project we add a reference to the assembly System.DirectoryServices.AccountManagement, and with the following short code the password of a user can be changed:

As one can see, we first create a PrincipalContext object. ContextType.Machine determines, that we want to access the local computer. From this we then select the desired user, and change its password.

Thursday, January 15, 2015

After I showed in the previous post how to publish new posts on Blogger using C# and the Blogger Data API v2, I want to show today how one can scan through the already existing posts on one's blog.
We do the same preliminary work like in the previous post, meaning we include Google.GData.Client and create the Service object, with which we log on.
With the following feed query we then can access all published posts:

FeedQuery query = new FeedQuery(); query.Uri = new Uri("http://www.blogger.com/feeds/" + blogID + "/posts/default"); AtomFeed feed = null; feed = service.Query(query);The following example program searches through the contents of all existing posts for the target expression "Test" and then returns the title of all matching posts:

Sunday, January 11, 2015

The next posts will be about the blogging portal Blogger.com, on which for example this blog is running. For the access via C# we need the Blogger Data API, as is described in this documentation. Here we use version 2, but there is already a (beta) version 3, which I will probably describe later.
In today's post I want to show, how to create and publish posts with C#.
For this we first have to download the Google_Data_API_Setup from this link and install it. Then we add a reference to Google.GData.Client.dll to our project, which is in my case located in the folder C:\Program Files (x86)\Google\Google Data API SDK\Redist, and integrate it to our project via using Google.GData.Client;
Now we can log on to Blogger:

Service service = new Service("blogger", ""); service.Credentials = new GDataCredentials(Email, Password); GDataGAuthRequestFactory factory = (GDataGAuthRequestFactory)service.RequestFactory; factory.AccountType = "GOOGLE";Posts are created in the atom format, with these lines of code we create posts with title "Test" and content "Testpost":

AtomEntry newPost = new AtomEntry(); newPost.Title.Text = "Test"; newPost.Content = new AtomContent(); newPost.Content.Content = "Testpost"; newPost.Content.Type = "xhtml"; // newPost.IsDraft = true;The attributes should be self explaining, via IsDraft we set whether the post should be a draft.
Finally we have to publish the post, for this we send the post to the blog feed, which is done like this: