Tag Archives: C#

Writing to the ULS in SharePoint 2010

Here’s a quick, easy, 3 step method to log your custom events to the ULS while writing a SharePoint 2010 solution:

  1. Add a reference to Microsoft.Office.Server (located in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI on your SharePoint server)
  2. Add a using statement at the top of your code like so:
    using Microsoft.Office.Server.Diagnostics;
  3. Add the following line wherever you want the message to appear in the ULS
    PortalLog.LogString()

See? That wasn’t so bad!

Eric Oszakiewski

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 36 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Development Lead for General Motors, and also as a consultant.

More Posts

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube

Visual Studio language support for C# not installed

What?  I just get a new dev laptop (yeah, pretty proud myself, HP Pavilion dv7, triple-core i5, 6GB RAM, 640GB HD, 17.3″ display…) and I install VS 2008 and 2010, SQL, etc.  Start working on an existing website using VS 2008 and it says “Visual Studio language support for C# is not installed.  Code-editing Intellisense will not be available.  Markup Intellisense for server controls may not work”.  You gotta be kidding me…

So I hit the googleverse and attempt to find a solution, since I know I’m not the only one who’s ever seen this before.  One site discusses a guy who completely removed all things Microsoft, reinstalled everything and it worked……seriously?  Finally happened to find this one”, thankfully!  Post is a year old but was entirely helpful!

All I did was close VS 2008, open a run prompt and type devenv /resetskippkgs and hit enter. VS 2008 opens and everything appears fine, but Intellisense is still missing.

I opened it in VS 2010 and Intellisense is fine.  I learned my lesson about hanging on to old technology…

Thank you!

Eric Oszakiewski

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 36 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Development Lead for General Motors, and also as a consultant.

More Posts

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube

Getting local IP address programmatically in Windows 7

I created a small client app for my company that required the local IP address (assigned by DHCP) to determine what site it was on. It reads the second octet value, which is consistent with each of our buildings in our enterprise. From here, I can determine what content to load so no matter where the PC is placed, it automatically grabs content only specific to that location.

Anyway, when testing this application on Windows 7 it doesn’t load any content. Initial troubleshooting indicates the IP address is not resolving as it would on a Windows XP machine. I dug into the code today and noticed when run on Windows 7 the IP Address was coming up something like this:

fe80::a0b4:2c9d:2542:6b73%11

This was achieved by using System.Net and the following C# code:

string hostname = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostEntry(hostname);
IPAddress[] ip = ipEntry.AddressList;

Then ip[0].ToString() will give you the IP Address, or in Windows 7 case, the IPv6 address you see above. Let me show you what worked for me:

First, make sure you’re referencing the System.Linq namespace in addition to System.Net.

Next, replace the above code with the following:

string hostname = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostByName(hostname);
string ip = ipEntry.AddressList.FirstOrDefault().ToString();

Note that Dns.GetHostByName is obsolete, and eventually will be replaced. However, the recommended “GetHostEntry” failed to return the IPv4 address I needed, but instead returned the IPv6 address mentioned above. I welcome feedback on what I might be doing wrong or how to improve on this process, but for now this solves my Windows 7 IP Address issue. Hope this helps someone else.

UPDATE: Thanks to the anonymous comment left that clarified my unfamiliarity with IPv6 address syntax. Corrections were made accordingly.

Eric Oszakiewski

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 36 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Development Lead for General Motors, and also as a consultant.

More Posts

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube

Excellent article on getting AD info using C#

I’m always getting, updating, and validating against AD info at my company, and today I needed to pull several different schema attributes in one method, and kept running into more and more trouble. Code got bigger and bigger, and I thought there had to be a way to simplify this. I then ran across a CodeProject article definitely worth mentioning. The author, Rajasekhara Sambangi does an excellent job of demonstrating a simplified way of pulling just about anything from AD by passing in the SearchResult object and the property name you’re searching for into a basic method, and the result is the value of the key! The link to the article is here.

Eric Oszakiewski

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 36 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Development Lead for General Motors, and also as a consultant.

More Posts

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube

New code library site

I created a basic code library site to host all of the code snippets I’ve gathered and/or created over time. Go here to visit the site.

It’s pretty basic and empty right now, I’ll dress it up a little more as time goes on. I’m also trying to determine a better way of sub-categorizing the code in each of the language tabs. I welcome suggestions. Enjoy!

Eric Oszakiewski

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 36 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Development Lead for General Motors, and also as a consultant.

More Posts

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube