Random Technical Thoughts

February 4, 2010

How to convert Timezones

Filed under: C# — Tags: — chrisbarba @ 9:54 pm

Here is a code sample (in C#) that I found for converting datetime between time zones.  This only works in the 3.5 framework (via System.TimeZoneInfo).

DateTime oldTime = new DateTime(2007, 6, 23, 10, 0, 0);
TimeZoneInfo timeZone1 = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
TimeZoneInfo timeZone2 = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime newTime = TimeZoneInfo.ConvertTime(oldTime, timeZone1, timeZone2);

 

Here is the url where I found this info.
http://pietschsoft.com/post/2007/06/23/NET-35-How-to-Convert-from-one-TimeZone-to-another.aspx

January 11, 2010

End user training for SharePoint 2010

Filed under: SharePoint 2010 — Tags: — chrisbarba @ 10:26 pm

If you need to provide end user training for SharePoint 2010 here is a link to some MS videos.

http://tinyurl.com/ybd46h6

Set default page for SharePoint publishing site

Filed under: SharePoint — Tags: — chrisbarba @ 10:08 pm

Here is a function that will set the default page for a publishing site.

Just pass in your web and the new default page name, it will take care of the rest.
Works great when creating new sites.

public static void SetPageAsDefault(SPWeb web, String pageName)
      {

          if (PublishingWeb.IsPublishingWeb(web))
          {

              PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);

              SPFile welcomefile = web.GetFile(pageName);
              if (null != welcomefile)
              {
                  publishingWeb.DefaultPage = welcomefile;
                  publishingWeb.Update();
              }
          }

      }

SharePoint set custom masterpage on site

Filed under: SharePoint — Tags: — chrisbarba @ 9:57 pm

Here is a function that will set a site (including sub sites) to use a custom masterpage.

You pass in the masterpage, web, and if you want to include sub sites (it will call itself with the sub site name).

public static void SetCustomMasterPage(string masterPage, SPWeb web, bool includeSubSites)
       {
           web.CustomMasterUrl = GetMasterPageUrl(masterPage);
           web.Update();

           if (includeSubSites)
           {
               foreach (SPWeb child in web.Webs)
               {
                   SetCustomMasterPage(masterPage, child, true);
                   child.Dispose();
               }
           }
       }

 

Hide SharePoint lists from Search

Filed under: SharePoint — Tags: — chrisbarba @ 9:47 pm

Here is a function that will hide a list from search.  This way custom lists created won’t be included in search results.

If you notice the pages library is excluded.  You don’t usually want to hide your content pages.

public static void ListHideFromSearch(SPList listToHide)
        {
            //Don’t ever hide the pages library
            if (listToHide.Title.ToLower() != "pages")
            {
                //Hide the list from search
                listToHide.NoCrawl = true;
                listToHide.Update();
            }
        }

 

Here is a blog post about how to accomplish this same thing through the UI.

How to get meaning from PerformancePoint error codes

Filed under: PeformancePoint Server 2007 — Tags: — chrisbarba @ 9:31 pm

If you have error codes from PerformancePoint and would like to get more meanings there is a function that will provide more information.

fn_util_evaluateValidationStatusCode (error code)

It should provide enough details to determine what is wrong.

January 6, 2010

Windows 7 GodMode (or 32bit Vista)

Filed under: Windows 7 — Tags: — chrisbarba @ 10:02 am

Windows 7 (or 32bit Vista) have a God Mode, which gives you all the settings of control panel in one folder (without having to browse around in control panel).

WARNING: THIS DOES NOT WORK ON 64bit Vista OR 64bit WINDOWS SERVER 2008.  DO NOT FOLLOW THESE INSTRUCTIONS IF YOU ARE RUNNING 64bit Vista OR 64bit WINDOWS SERVER 2008.  IF YOU DO EXPLORER.EXE WILL REBOOT OVER AND OVER. 
Here are the instructions for removing GodMode, http://chrisbarba.wordpress.com/2010/01/06/how-to-remove-godmode-from-vista-64bit/

GodMode

Here are the instructions for adding a GodMode folder.
Right click on the desktop and add a new folder.
Name it the following GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}

After that you will have this folder on your desktop.

How to remove GodMode from Vista (64bit)

Filed under: VISTA — Tags: — chrisbarba @ 10:01 am

So my friend Dennis blogged about GodMode so I thought I would give it a try.

Yeah, don’t do it on 64bit Vista.

If you made the mistake of trying to create a GodMode folder on 64Bit Vista (or Windows Server 2008), then explorer.exe will restart over and over.

So how do you get of the folder?  You have 2 choices.
1) You can go to another computer and browse to the desktop on your computer (\\computername\users\USERNAME\desktop\) and delete the GodMode folder.

2) If you have trouble with this (or don’t have another computer) then you can reboot into safe mode command prompt.  Then you can change directories to the desktop (cd c:\users\USERNAME\desktop).  Then run the following command: rd /s “GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}”   Click Y, when asked.

(You can also rename the directory and delete it after you reboot).

Then reboot and everything should be back to normal

January 3, 2010

Clear Controls on screen

Filed under: ASP.NET, C# — Tags: — chrisbarba @ 11:33 pm

Here is a method that will clear all the controls on your screen (as long as it matches one of the controls in the method).  It recursively calls itself until all the controls are clear.

Here is an example of how you call it:
ClearControlsOnScreen(this.Page);

 

  public void ClearControlsOnScreen(Control parent)
        {
            try
            {
                foreach (Control _ChildControl in parent.Controls)
                {
                    if ((_ChildControl.Controls.Count > 0))
                    {
                        ClearControlsOnScreen(_ChildControl);
                    }
                    else
                    {

                        TextBox textbox = _ChildControl as TextBox;
                        if (textbox != null)
                        {
                            textbox.Text = string.Empty;
                        }

                        DropDownList dropdownlist = _ChildControl as DropDownList;
                        if (dropdownlist != null)
                        {
                            dropdownlist.ClearSelection();
                        }

                        CheckBox checkBox = _ChildControl as CheckBox;
                        if (checkBox != null)
                        {
                            checkBox.Checked = false;
                        }

                        CheckBoxList checkBoxList = _ChildControl as CheckBoxList;
                        if (checkBoxList != null)
                        {
                            checkBoxList.ClearSelection();
                        }

                        GridView gridView = _ChildControl as GridView;
                        if (gridView != null)
                        {
                            gridView.DataSource = null;
                            gridView.DataBind();
                        }

                    }
                }

            }
            catch (Exception ex)
            {
                throw ;
            }
        }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Run app as a specific user

Filed under: C# — Tags: — chrisbarba @ 11:22 pm

Running an application as a specific user is common practice, but sometimes it’s helps to debug your application if you can run it as a specific user.

This does not change security context which the application runs as.
This works if you have your own user/role tables that control application security.

So if you add a key to your config file (web.config for example) then anytime you need to get the current user just call this method.

If the strUsername key is set to “Default” it will run as the current user.
If you set it to some other username it will return that username.

public static string GetUsername()
        {
            try
            {
                if (System.Configuration.ConfigurationManager.AppSettings["strUsername"].ToString() == "Default")
                {
                    return HttpContext.Current.User.Identity.Name.Substring(HttpContext.Current.User.Identity.Name.IndexOf('\\') + 1).ToLower();
                }
                else
                {
                    return System.Configuration.ConfigurationManager.AppSettings["strUsername"].ToString();
                }
             }
            catch (Exception ex)
            {
                throw ;
            }
        }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Older Posts »

Blog at WordPress.com.