2 Des 2011

Tips: Simplify your ‘OR’ Logic in C#.NET

I think I do have a little tips for you to share. Not very significant tips, but you can use it for your daily practice.

Sometimes when you want to use a logic like this, it’s too long to write code.

Old Code
  1. if (Fld.Type == SPFieldType.Choice || Fld.Type == SPFieldType.Note || Fld.Type == SPFieldType.Integer || Fld.Type == SPFieldType.Number)
  2.     FieldContent = (string)Li[Fld.Id];

But you can simplify your code using this code below.

Simpler Code
  1. if (",Text,Note,Choice,Integer,Number,".Contains(Fld.TypeAsString))
  2.     FieldContent = (string)Li[Fld.Id];

Happy coding…! Winking smile

24 Nov 2011

Take Screenshot of your Android Devices

How to take a screenshot on Android? A little stupid isn’t it? I’m currently working with Microsoft Products, but my device for daily and mobile email is based on Android. But I think I’m not the only one. Microsoft a little s**ks but I made a money, got a cool job because of their products, and became better understanding in IT Products and lifecycles. Well, as long as it’s an IT tips, I think it’s OK.

Here’s a little tips for you, if you don’t know it. Press and hold Home button and then right away press Power button (see screenshot of Samsung Galaxy Y, with red mark), then you’ll got your screenshot of your Android devices automatically in your SD Card. AFAIK, this will work in Android 2.3 Gingerbread. For Android 2.2 Froyo, AFAIK, may vary, some says that press and hold back button and then right away press Home button.

21 Okt 2011

Get All Items including inside SharePoint Folder Programmatically using SPQuery

Just sharing the knowledge, I want to share about how to get all items / documents programmatically without getting inside the folder and querying it again. So, without folders, all items whether inside a folder or not, will be shown upon your query result.

Awwww, I’m not in Windows 2008 mode to copy my code in here and show some screenshots, but that’s just fine.

Using RecursiveAll in SPQuery
  1. SPQuery Q = new SPQuery();
  2. Q.Query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>BOOK</Value></Eq></Where>";
  3. Q.ViewFields = "<FieldRef Name='Name' /><FieldRef Name='ID' />";
  4. Q.ViewAttributes = "Scope='RecursiveAll'";

After you code your query, then you can add ViewAttributes and add Scope=’RecursiveAll’ to the SPQuery object.

Done, and all items whether inside a folder or not, will be shown upon your query result.

18 Okt 2011

Tools to Get SPSite and SPWeb Aggregation ID for SharePoint 2010

It’s been a busy months for me, I can’t write anything on my spare time. But I tell you what, I’ve created a little tools to generate Aggregation ID so you don’t have to write code about it if you just want to query the Web Analytics on SharePoint 2010.

Just specify your URL and Level, and you’re good to go.

image

Usage:
Rdz.GetAggregationId.exe –URL <URL of SharePoint Site or SubSite> –Level [SPSite | SPWeb]

Below is the exe file that you can use. It based on .NET 3.5.

UPDATE: Thanks for Anand for noticing. I just realized that I haven’t include the DLL inside the ZIP file yet. Above, is the updated link. Thanks a lot and sorry for my mistake! Open-mouthed smile

20 Jul 2011

Tips for Different FQDN and NetBIOSName in SharePoint 2010 User Profiles

SharePoint, SharePoint, and SharePoint again. Today I want to post something about how we can import from Active Directory but with the FQDN and NetBIOSName completely different. If your domain FQDN is (for example) gembelcorpse.co.id, and your NetBIOS Name set to GC, then you do have a problem. When you let this SharePoint User Profile imports from your active directory, it will make the User Profile import like GEMBELCORPSE\administrator, or GEMBELCORPSE\user1, and that’s totally wrong.

In the previous version of SharePoint (2007), we don’t need to do this tips, all things are automatically done by system. Now, in SharePoint 2010, we must do this kind of tips. So, take a look at this PowerShell code.

Code Snippet
  1. param($ServiceApplicationName)
  2. $ServiceApps = Get-SPServiceApplication
  3. $UserProfileServiceApp = ""
  4. foreach ($sa in $ServiceApps)
  5.   {if ($sa.DisplayName -eq $ServiceApplicationName)
  6.     {$UserProfileServiceApp = $sa}
  7.   }
  8. if ($UserProfileServiceApp -eq "")
  9. {
  10.     Write-Host "Ooops..., Service Application '$($ServiceApplicationName)' not found."
  11. }
  12. else
  13. {
  14.     Write-Host "Found '$($UserProfileServiceApp.DisplayName)'..."
  15.     if ($UserProfileServiceApp.NetBIOSDomainNamesEnabled -eq 1)
  16.     {
  17.         Write-Host "NetBIOSDomainNamesEnabled in '$($UserProfileServiceApp.DisplayName)' already enabled, nothings updated!"
  18.     }
  19.     else
  20.     {
  21.         Write-Host "Press any key to continue, [Esc] to cancel..."
  22.         $Key = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
  23.         if ([int]$Key.Character -eq 27)
  24.         {
  25.             Write-Host "Canceling update to '$($UserProfileServiceApp.DisplayName)'..."
  26.         }
  27.         else
  28.         {
  29.             $UserProfileServiceApp.NetBIOSDomainNamesEnabled = 1
  30.             $UserProfileServiceApp.Update()
  31.             Write-Host "Done Updating '$($UserProfileServiceApp.DisplayName)'!"
  32.             Write-Host "Please run Full Synchronization to import all User Profile."
  33.         }
  34.     }
  35. }

With that PowerShell code, run it using SharePoint PowerShell, you can run it from Start menu > Microsoft SharePoint 2010 Products > SharePoint 2010 Management Shell.

image

Run it using –ServiceApplicationName argument. If your User Profile Service Application Name is User Profile SSA, then you should run it like this command below.
.\SP2010EnableNetBIOSName.ps1 -ServiceApplicationName "User Profile SSA"

image

NOTE: You must run this script on a newly created User Profile Service Application. If you already have the existing, you must delete it, or create another User Profile Service Application. Don’t do the Full Synchronization, configure it first (point to active directory), and then run this script, and then run the Full Synchronization of your User Profile Service Application.

Nice….! click +1 if you do like Winking smile

8 Jul 2011

Get SharePoint User Profile of Specific User Programmatically

Again, I want to share some of my encapsulated methods. So, I’ve been through so many projects, developing this and that, with the same pattern. It very helpful when you choose to use encapsulation and get it for later use.

This method is about get SharePoint user profile. You can use this code whether you are using SharePoint 2007 or SharePoint 2010. Enjoy… Winking smile

Code Snippet
  1. public static UserProfile GetUserProfile(string LoginName)
  2. {
  3.     return GetUserProfile(SPContext.Current.Site, LoginName);
  4. }
  5. public static UserProfile GetUserProfile(SPSite Site, string LoginName)
  6. {
  7.     return GetUserProfile(Site, LoginName, true);
  8. }
  9. public static UserProfile GetUserProfile(SPSite Site, string LoginName, bool RevertSystemAccount)
  10. {
  11.     //check if SharePoint System Account
  12.     if (IsSharePointSystem(LoginName) && RevertSystemAccount)
  13.         LoginName = Site.WebApplication.ApplicationPool.Username;
  14.     SPUser Usr = Site.RootWeb.EnsureUser(LoginName);
  15.     ServerContext SCtx = ServerContext.GetContext(Site);
  16.     UserProfileManager UPM = new UserProfileManager(SCtx);
  17.     if (UPM.UserExists(Usr.LoginName)) { return UPM.GetUserProfile(Usr.LoginName); }
  18.     else return null;
  19. }

Write and Delete Settings to .NET App.Config or Web.Config

I don’t have anything to post Where, but I think this might be useful for you. Want to write and delete appSettings in App.Config or Web.Config? Sure you do know how to read it.

Hope this little code helps

Code Snippet
  1. namespace Rdz.Utility
  2. {
  3.     public static class ConfigUtility
  4.     {
  5.         /// <summary>
  6.         /// Writes to configuration file (App.Config) to specified key, or creates a new Key if doesn't exist
  7.         /// </summary>
  8.         /// <param name="KeyName">The Application Settings KeyName</param>
  9.         /// <param name="Value">The Application Settings Value</param>
  10.         public static void WriteToAppConfig(string KeyName, string Value)
  11.         {
  12.             Configuration cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  13.             if (cfg.AppSettings.Settings.AllKeys.Contains(KeyName))
  14.                 cfg.AppSettings.Settings[KeyName].Value = Value;
  15.             else
  16.                 cfg.AppSettings.Settings.Add(KeyName, Value);
  17.             cfg.Save(ConfigurationSaveMode.Modified);
  18.             ConfigurationManager.RefreshSection("appSettings");
  19.         }
  20.  
  21.         /// <summary>
  22.         /// Deletes specified key in app.config
  23.         /// </summary>
  24.         /// <param name="KeyName"></param>
  25.         public static void DeleteAppConfig(string KeyName)
  26.         {
  27.             Configuration cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  28.             if (cfg.AppSettings.Settings.AllKeys.Contains(KeyName))
  29.             {
  30.                 cfg.AppSettings.Settings.Remove(KeyName);
  31.                 cfg.Save(ConfigurationSaveMode.Modified);
  32.             }
  33.             ConfigurationManager.RefreshSection("appSettings");
  34.         }
  35.     }
  36. }

Cheers… and happy coding! Hihi...

9 Jun 2011

Add OOTB Rating Control in SharePoint 2010 Blog Site

Again, this is really bad I think Confused smile. Rating Control doesn’t exist in Blog template site in SharePoint 2010, even if you have activated Rating feature in Posts list. I think there’s a good solution out there in internet, but I have a different one. It’s not the best solution I think, but can be comparable. The easy way, but good enough.

6 Jun 2011

My Development Environment to Develop SharePoint 2010 Solutions

Well, I don’t know if this tips would help much for you. But this is my best Development Environment when I want to create SharePoint 2010 Solutions. And I’m about to share to you all, so I hope it helps.

My Development Environment (DE) is using Windows 2008 R2. But I’m adding some UI feature for extra comfort usability, and more like Windows 7, and of course, Kung Fu Panda 2 themes, downloaded from Microsoft’s theme pack website Smile with tongue out. And not only that! I want my development environment works faster, faster to deploy (well, at the first deploy, you can’t refuse if it slower, but better on next deployment), faster to install DLL, and recycle IIS, and faster to debug IIS processes.

Recycle IIS Application using Command Line

I’m actually don’t know if there’s an application which can recycle IIS Application Pool using command line, but I haven’t found one. So, I would like to create this small app.

And, here’s the screenshot.
image

image

image

I hope the app could help you all. It’s based on .NET Framework 2.0 (CMIIW Smile with tongue out). And I’m sure it’ll comin’ handy.
Here’s the link, enjoy.

Tips: Set Default SharePoint Content Database in Web Application

This day I would like to write a small tips, simple but useful tips to maintain your SharePoint Database growth. Basically, when you create a web application, you must configure the Web Application, the SQL Database name for Default Content Database. For a serious disk space matter, if in your web application in the next implementation will be used as Document Center, or anything else which needs a big space, you might want to separate your Default Content Database for each Site Collections.

You could have multiple Content Database, but you don’t know what is the default Content Database if you create a Site Collection. Well, I think this is not the trick, but a small tips and feature that you sometimes doesn’t realize it exist.

19 Mei 2011

How to Get SharePoint 2010 Web Analytics Programmatically? Finally Found!

You probably know that one biggest challenge is how to get SharePoint 2010 Web Analytics data in Web Analytics Report programmatically. It’s a little stupid (I suppose) if Microsoft doesn’t provide API to access this cool feature. Although there’s an API in a method like GetUsageData(), but this thing doesn’t enough. We want more detailed and mimicking the SharePoint Web Analytics Report.Where

I’d rather write my own code about HttpModule or use a third party Analytics feature like Google Analytics than searching entire database for those kind of reports. But, that’s just became a nightmare if you see that the portal is not published to the Internet.

Well, after 2 days full searching (really – no sleeping at all Surprised smile) in entire SharePoint 2010 Web Analytics Database, I found how to do it. By the way, accessing Database generated by SharePoint 2010 isn’t really supported by Microsoft. But I think it’s OK as long as you don’t write or update any data to them, go on, express yourself.

21 Mar 2011

Hide “Revert to Template” in Modified SharePoint 2010 Wiki Page

OK, I see a lot of solutions about this, but many of them wasn’t a good solution for me. These are the solution links:
Why the message "Revert to Template” always shown?
When you create Wiki Pages using Out of the box SharePoint, actually the page you’ve created was marked and created based on Site Definitions. So, you need to create the page which isn’t marked as “based from Site Definitions” page.
Actually, the solution from Dalibor MSFT was simple enough and not involving any hard customization. Here’s the solution:
Open your site in SharePoint Designer 2010.
image
Open Site Pages library.
image
Right click on empty space, point to New and then ASPX.
image
Open the modified page using right click, and then Edit File in Advanced Mode.
image
Copy all of the markups.
image
Paste it in the newly created ASPX file, save the file, and you’re done!

14 Jan 2011

Page Not Shown when Opening SharePoint from Web Front End Server

Remember, this is the normal behavior of SharePoint and Windows Server! You’ll be prompted for username and password three times before it’s blanking and not showing anything.

This is really annoying especially when you want to debug your SharePoint site. Microsoft says that when you accessing your site internally (inside from Web Front End Server) using FQDN (Fully Qualified Domain Name), you’ll be prompted username for several times, and then blank. Just blank. But why? They said that to prevent attack from hackers or some stupid guy with no future, trying to hack your site.

This is how to make it up. Open Regedit.exe in your server and find HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa key. If you don’t have one, create one DWORD value (32-bit) with the name DisableLoopbackCheck, and set the value to 1.

That’s it. Recycle your Application Pool, and try to access the SharePoint site inside.

7 Jan 2011

Multiple Gateway on Different Network Interface

Hello, I’m back and writing again after doing some work. This day I want to talk about multiple gateway. A little tips but it’s good for your daily work, and helping much. My case is when I got to go to the client, and there’s no internet connection on their LAN. I have a modem to connect to the internet, but I want to connect both networks together, how am I able to do that?

Actually it’s simple enough to do that. When you look at Microsoft.com tutorial, it’s too complicated. But in my experience, it’s preety simple.

  1. Configure the default gateway for NIC with the most routes. Usually the network adapter that’s connected to internet. In my case, I don’t need to setup default gateway, coz it’s DHCP when I connect to my modem.
  2. Configure the second NIC which isn’t connected to internet a.k.a LAN, with the static IP, and DNS of your network. But please, just make the default gateway empty, just like this example picture below.
    image
  3. Find the ID of your LAN’s Interface. To do this, open the Command Prompt and type “ROUTE PRINT” (without quotes). My LAN NIC is Realtek, and the ID is 12.
    C:\Users\Administrator>route print
    ===========================================================================
    Interface List
    16...00 f1 d0 00 f1 d0 ......GlobeTrotter HSxPA - Network Interface
    14...02 00 4c 4f 4f 50 ......Microsoft Loopback Adapter
     12...00 23 5a a9 eb 5f ......Realtek RTL8102E/RTL8103E Family PCI-E Fast Ethernet NIC (NDIS 6.20)
      1...........................Software Loopback Interface 1
    13...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter
    15...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #2
    17...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #3
    ===========================================================================
  4. In my LAN, all IPs are started with 10.xxx.xxx.xxx, and the gateway is 10.200.200.7. This step, open Command Prompt and type this “ROUTE ADD 10.0.0.0 MASK 255.0.0.0 10.200.200.7 IF 12” (without quotes).
    C:\Users\Administrator>route add 10.0.0.0 mask 255.0.0.0 10.200.200.7 if 12
    OK!

If it’s “OK!” and then nothing’s to be worried. Your job adding route is done. Now I can remote another server in LAN, and connecting to the Internet through my modem without closing another network.