CJ

The circle of life – ** .Net – Training – MOSS **

  • Past Post

  • Vistor Locations

Test in Multiple Browsers

Posted by CJ on May 29, 2009

This has always been a problem for developers with requirements to support multiple browsers. When writing code various browsers render the exact same peice of code differently. So the development process consists of programming workarounds so they render the same or very similar.

Now we have a free tool that we can use to test multiple browsers easily during our development process.

http://www.xenocode.com/browsers/

Posted in .NET 2.0, .Net 3.0 | Leave a Comment »

Add .Net User Controls to SharePoint

Posted by CJ on May 25, 2009

I have been developing inside SharePoint for a while now and while things are getting easier with tools I think this process for developing User Controls inside SharePoint gives me a lot of control.

  1. I have a Graphical User Interface
  2. I have a separate project to build and test outside of SharePoint
  3. I can easily update and view my project html and binary code

Currently this process doesn’t create me any SharePoint Solution files to deploy across environments. I think to achieve this I will need to create a VS 2008 SharePoint Project…but so far these projects seem to add weight and time that I don’t want at the moment…while I am developing.

  1. Create a VS2008 web project
  2. In IIS create an IIS Application under your SharePoint web site that has a path to your VS2008 web project created above. This helps for updating content
  3. In your VS2008 project create some user controls and test that they function
  4. In VS2008 project properties under the Build Events tab point the Post Build events text box and add a copy statement to copy your .dlls and .pdbs to your SharePoint web sites bin directory. This will deploy a new .dll every time you build your VS2008 project. I had problems when I put the VS2008 project .dll into the GAC…it only worked when I put it into the SharePoint’s web sites bin directory
  5. Update your master page with CSS references if your VS2008 project contains a style sheet.
  6. In SPD in your Page Layout add a Register directive to register your user control
    “<%@ Register Src=”~/UI/UserControls/JobGoals.ascx” TagPrefix=”uc1″ TagName=”JobGoals” %>”
    OR
    Update the SharePoint web site web.config file
    <pages>
      <controls>
            <add src=”~/UI/UserControls/MyAttributes.ascx” tagPrefix=”uc1″ tagName=”MyAttributes”/>
            <add src=”~/UI/UserControls/JobGoals.ascx” tagPrefix=”uc1″ tagName=”JobGoals” />
        </controls>
    </pages>
  7. Add the User Control to the Page Layout
    <uc1:JobGoals ID=”JobGoals1″ runat=”server” />
  8. Update the SharePoinnt web sites web.config file
    <SafeControl Src=”~/UI/*”  IncludeSubFolders=”True” Safe=”True” AllowRemoteDesigner=”True” />
  9. Restart IIS, navigate to a page that uses the page layout and you should see your User Control

Because we created a IIS Application under our SharePoint web site and mapped our VS2008 projects .dll output path to our SharePoints web site, updates are extremely simple.

  1. .ascx changes:                modify, save in VS2008 and refresh sharepoint browser
  2. .ascx.cs changes:          modify, save, build  in VS2008 and refresh sharepoint browser

Posted in .NET 2.0, .Net 3.0, WSS 3.0 | 1 Comment »

User Group Presentation – Content Query Web Part – Part 2

Posted by CJ on May 20, 2009

I completed my Part 2 presentation on the CQWP today. I thought that the rain may have kept the numbers down so it was great to see a good turn out.

Topic Covered:

  • How and where best to use – plan ahead
  • Displaying extra columns in result set
  • Modifying the ItemStyle.xsl and .webpart files
  • XSLT
  • Tips and tricks – (thanks Tim for the select=.) tip
  • Subclassing using Visual Studio
  • Deployment

 

I always need more time presenting at user groups.

Slide deck and demos will be uploaded to the BSPUG site soon.

Posted in MOSS 2007, Presentaitons | 1 Comment »

SharePoint Authentication: FireFoxs works but IE doesn’t

Posted by CJ on May 20, 2009

I was having a great deal of pain on a new SharePoint development server recently. Environment = Windows 2008, IE7.

Situation

  1. Create a SharePoint web application with a host header on port 80. Create a site collection
  2. Update host file (or DNS) with new host header entry
  3. In IE make sure the web application is in the Intranet Zone
  4. Open up browser in IE navigate to site using host header and the authentication dialog login is displayed.
  5. Enter my credentials 3 times and receive a 401.1 and an entry in the Security Event log
  6. If I open FireFox and browse to the web site the authentication dialog is displayed
  7. I enter my credentials and I can log in fine
    Note: To get rid of the authentication prompt in FireFox
    1. Open FireFox and in the address type about:config
    2. Find the entry network.automatic-ntlm-auth.trusted-uris
    3. Set the Key’s value to a comma seperated list of trusted URIs i.e your host header
  8. So FireFox is fine but IE is having issues

 

Solution

I finally stumbled across a blog article from Brian Farnhill and Ishai Sagi that lead me to the solution.

You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or IIS 6
http://support.microsoft.com/default.aspx/kb/896861

In my case I am using IE 7 and while the Solution/Workaround discusses two separate methods and states that method one is preferred, I could only fix my issue upon completing method 2

Posted in MOSS 2007, Office 12, WSS 3.0 | Leave a Comment »

Accessibility Resources

Posted by CJ on May 15, 2009

A list of useful accessibility resources

Microsoft ASP.Net

SharePoint Specific

Tools

Posted in .NET 2.0 | 1 Comment »

Importing AD Employee Photos into SharePoint User Profiles

Posted by CJ on May 8, 2009

I was recently asked to provide a process for importing Employee pictures into SharePoint so they would show up in search results and various OOTB web parts. This particular client has MOSS but doesn’t use My Sites.

This post by Henry initially helped me out.

They didn’t want the individual users to have the abilty to upload their own photo’s or modify them in any way, this was to be managed by IT.

  1. Create a Picture Library in your Intranet. This will store the photo’s for each employee. When storing employee photo’s chose the filename carefully if you want to populate the AD using scripts. I use something like cjames.jpg which is a correlation to the users account name.
  2. In Active Directory choose an AD property that will be mapped to your SharePoint User Profile Property. In my case I selected the extensionAttribute1 field that is located in the ExchangedAdvanced tab ((note this field may not show up if the Exchange Mgt Console hasn’t been installed)
  3. Populate this field with the URL to the employee’s photo that is in the Picture Library e.g http://sitename/ProfilePhotos/CJames.jpg (look below for a script example)
  4. In SharePoint SSP click the User Profiles and Properties link
  5. Click the View Profile Properties under the heading User Profile Properties
  6. Find the Picture property and select the Edit menu item
  7. Make note of the Usage: Number of profiles using this property. This should increase after we complete a full import
  8. At the bottom of the screen make sure Master Connection is selected and in the Datasource field to map select extensionAttribute1 (note: this field may not show up if the Exchange Mgt Console hasn’t been installed)
  9. Click Ok
  10. Complete a StartFull Import
  11. Once the full import is complete go back into the the Picture property and again check the Usage:Number of profiles that use this property. This should now contain some values.
  12. Verify this by viewing an Employee’s profile and the Picture property

Some things I had issues with:

  • Make sure your Import Connection service account has “Manage User Profile” permissions
  • May need to execute a Full Search crawl once photos are uploaded in the Picture Library

I also wrote a script to populate the AD extensionAttribute1 field as there were over 1000 employee’s and no one put their hand up for this job. The import thing here was for employee photo images to have a one to one mapping with their login account name (samaccountname). The person who runs this script also needs certain permissions in AD to update AD accounts. I would initially comment out the On Error Resume Next so you see if your account has enough privleges or not.

The script is very limited but hopefully it may provide some insight.

‘On Error Resume Next
Set objParent = GetObject(”LDAP://OU=Users,OU=Austraila,OU=Offices,OU=AU,DC=domain,DC=local“)
objparent.Filter = Array(”user”)
for each objUser in objParent
  Wscript.Echo “Modifying ” & objUser.Get(”samaccountname”) 
  objUser.put “extensionAttribute1″, “http://sitename/ProfilePhotos/” & objUser.Get(”samaccountname”) & “.jpg”
  objuser.Setinfo   
next

Wscript.Echo “End”

Now, IT are responsible whenever they create a new account they must also populate the extensionAttribute1 field with the URL of the picture library and the employee’s picture filename will always be their account name.

Posted in MOSS 2007, Office 12 | 5 Comments »

Sign in as a Different User

Posted by CJ on May 7, 2009

This little feature has caused myself so many problems for different clients. Some of the main issues I have come across include:

  • Still runs .Net code under the person who has logged into the computer
  • Creates authentication issues for end users when trying to open an Intranet bowser. Have to remove their user profiles to fix

I recommend to anyone now to find the IExplore.exe (right click your shortcut and select Properties, then click the  ”Find Target” button), right click and select the ”run as”. Enter the credentials of the user you wish to log in as.

This still won’t run .Net code under the new credentials you have entered but I have not come across any authentication issues using this approach so far.

Posted in WSS 3.0 | Leave a Comment »

Non-Admins View Site Usage Reports

Posted by CJ on May 5, 2009

How to get non-admins to view your site collection and site usage reports

Site Collection Admins or user will Full Control can view Site Collection and Site Usage Reports.  So if you want other users to access these reports you can do the following:

  1. Create a custom site permission level and select the “View Usage Data” check box
    Note: this will also select the “View Pages” permission
  2. Create a new Group called something like “Usage Report Viewers” and assign the permission level you created above to the group
  3. Add the people you want to view the reports
  4. Provide the users with links to the report pages
    1/ http://sitecollection/_layouts/SpUsageSite.aspx - view site collection reports
    2/ http://sitecollection/_layouts/SpUsageWeb.aspx - view site reports

Use a web part to display the links and above and audience targeting so only the users in the SharePoint group “Usage Report Viewers” see the web part.

Posted in WSS 3.0 | Leave a Comment »

Handling.Net DataSets correctly

Posted by CJ on March 18, 2009

One of the most common programming issues I see when working at clients locations is the way the common .Net DataSet is managed. I see a lot of code written like the first example below which checks if the DataSet table contains any rows. The problem with Example 1 is it expects a couple of things. Firstly that a DataSet (ds) even exists and secondly that it also contains a table. This code will throw an exception if the DataSet is null or no DataSet table exists.

Example 1
//this will throw an exception if ds is null or no table exists
if(ds.Tables[0].Rows.Count > 0)
{
            //process data
}

Example 2
So you should write your code checking of empty rows, empty tables and if the DataSet object exists.
if(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
            //process data
}
else
{
         // it is empty
}

 

Happy Coding! :)

Posted in .NET 2.0 | Leave a Comment »

IFrame Resize and SharePoint

Posted by CJ on March 3, 2009

I created a custom IFrame web part that has a dynamic source property. The client wanted the IFrame to dynamically resize itself to the browsers width and height.

 

To achieve this we needed to place the web part directly into the page i.e don’t use a webpart zone. A web part zone wraps tables around the IFrame and controls the width and height properties.

 

I read a few articles about using JQuery….may have to give this a go also.

Posted in .NET 2.0 | Leave a Comment »

User Group Presentation

Posted by CJ on February 17, 2009

I will be presenting at my local SharePoint user group tomorrow. This will actually be my first SharePoint user group presentation so I am really looking forward to meeting some new people and seeing what is happening in the SharePoint space.

I am talking about the Content Query Web Part and the abstract is below.

Leveraging the Content Query Web Part

Come and learn how to configure one of the most important MOSS web parts in your toolkit. We will walk-through SharePoint’s premier OOTB rollup web part and demonstrate how to display results in 2 or 3 column format and have multiple fields returned in the results. We will also open Visual Studio and demonstrate how to extend its functionality with paging and dynamic filtering.

 

If you would like to attend then the details are below.

clip_image001

Posted in .NET 2.0 | 1 Comment »

CAS & Web Parts

Posted by CJ on January 10, 2009

Brett Lonsdale has done some great work in documenting CAS in SharePoint. I recently used two of his articles to get my assemblies working.

http://www.brettlonsdale.com/spblog/Lists/Posts/Post.aspx?ID=7

http://www.combined-knowledge.com/Downloads/Code%20Access%20Security%20in%20SharePoint%202007%20for%20Administrators.pdf

 

The CAS Bible – old but still very relevant
http://msdn.microsoft.com/en-us/library/ms916855.aspx#sharepoint_wsscodeaccesssecurity_topic5

 

Great work from Patrick about grouping assemblies to share CAS policies using the same .snk file.
http://www.u2u.info/Blogs/Patrick/Lists/Posts/Post.aspx?ID=1798

 

Good explanation
http://daniellarson.spaces.live.com/blog/cns!D3543C5837291E93!1963.entry
http://dotnettipoftheday.com/Blog.aspx?Id=371

Posted in .NET 2.0 | Leave a Comment »

SharePoint December Cumulative Updates

Posted by CJ on January 9, 2009

I have just updated my development (Single Server with SQL Server installed) SharePoint machine with the WSS and MOSS December updates. Note there are two updates if you are running MOSS.

To my surprise everything worked a treat.

I only had SP1 installed before I installed the December updates. I didn’t have the Infrastructure update or any other hotfixes installed before applying the updates.

Steps

  1. I installed the WSS update first.
  2. I didn’t run SharePoint Configuration wizard
  3. I installed the MOSS update
  4. I did run the SharePoint Configuration wizard

 

The great thing about the December update is that it includes all previous hotfixes from RTM.

Read and download them from here.
http://blogs.msdn.com/sharepoint/archive/2008/12/17/announcing-december-cumulative-update-for-office-sharepoint-server-2007-and-windows-sharepoint-services-3-0.aspx

Posted in .NET 2.0 | Leave a Comment »

How to add a webpart into a special group other than miscellaneous

Posted by CJ on January 8, 2009

By default, SharePoint web parts are always put into a web part group called “Miscellaneous”.

If you want to automate this process when deploying your web parts as a Feature you can do the following:

In your web parts element manifest file

<ElementManifests>
    <ElementManifest Location=”MyWebPart\MyWebPart.xml” /> this is the file you edit
    <ElementFile Location=”MyWebPart\MyWebPart.webpart” />
  </ElementManifests>

 

Add the following elements

<Module Name=”WebParts” List=”113″ Url=”_catalogs/wp”>
      <File Path=”FlarePoint.MyWebPart.webpart” Url=”FlarePoint.MyWebPart.webpart” Type=”GhostableInLibrary”>
          <Property Name=”Group” Value=”FlarePoint Web Parts” />this is what you add for the Group
          <Property Name=”Title” Value=”FlarePoint.MyWebPart” />this is what you add for the Title
          <Property Name=”WebPartDescription” Value=”FlarePoints MyWebPart description” />this is what you add for the Description
      </File>
  </Module>

Good post on doing this via the object model
http://blogs.msdn.com/cliffgreen/archive/2008/04/18/adding-web-parts-to-the-web-part-gallery-using-the-sharepoint-object-model.aspx

Posted in .NET 2.0 | 1 Comment »

DataView vs DataForm

Posted by CJ on January 6, 2009

I was looking into the differences between the DataViewWebPart and the DataFormWebPart today and I found little information on this topic until I finally came across a SPD blog entry:

http://blogs.msdn.com/sharepointdesigner/archive/2007/04/24/spdatasource-and-rollups-with-the-data-view.aspx

Data View vs. Data Form

Before we go deeper, you may have noticed that many of us use “Data View” and “Data Form” rather interchangeably. In Windows SharePoint Services v2, we shipped a web part called the DataViewWebPart (DVWP). This web part uses XSLT to transform data from Data Retrieval Services to HTML. In Windows SharePoint Services v3, we shipped a web part called the DataFormWebPart (DFWP). The DataFormWebPart still uses XSLT, but now uses ASP.Net 2.0 Data Source Controls for data access. In addition to “view” functionality, the DataFormWebPart also introduced “form” functionality to write back to various data sources. We use Data View generically to refer to the feature set and all of SharePoint Designer’s UI still uses the term Data View.

Posted in .NET 2.0 | Leave a Comment »

Add Web Part to page using code

Posted by CJ on December 31, 2008

     // add Content Editor Web Part
     SPFile NewPage = Web.GetFile(NewPageUrl);
     SPLimitedWebPartManager mgr;
     mgr = NewPage.GetLimitedWebPartManager(PersonalizationScope.Shared);

     ContentEditorWebPart wp1 = new ContentEditorWebPart();
     wp1.Title = txtPageTitle.Text;
     wp1.ChromeType = PartChromeType.TitleOnly;
     wp1.AllowClose = false;
     XmlDocument doc = new XmlDocument();
     string ns1 = “http://schemas.microsoft.com/WebPart/v2/ContentEditor”;
     XmlElement elm = doc.CreateElement(”Content”, ns1);
     elm.InnerText = txtPageContent.Text;
     wp1.Content = elm;

     // add Web Part to Left Zone
     mgr.AddWebPart(wp1, “Left”, 0);

Posted in .NET 2.0 | 1 Comment »

Silverlight

Posted by CJ on December 16, 2008

Andy is developing a some user controls that allow blend designers to draw objects and translate these into Physics objects.

Check out his cool little demos here.
http://www.andybeaulieu.com/Default.aspx?tabid=67&EntryID=128

I think in 2009 Silverlight will come of age and in 2010 it will burst into mainstream! Just you wait and see :)

Posted in .NET 2.0 | Leave a Comment »

DropDownList FindByText FindByValue

Posted by CJ on November 27, 2008

Am always looking for this code snippet.

If you try to do this, you will not achieve the desire results:

 

ddlList1.SelectedItem.Text = dropdownValue;

 

By doing that, it will overwrite existing items. Not a good idea at all. Try this instead; you can either set FindByText or FindByValue.

 

ddlList1.SelectedIndex = ddlList1.Items.IndexOf(ddlList1.Items.FindByText(dropdownText));

 

Or

 

ddlList1.SelectedIndex = ddlList1.Items.IndexOf(ddlList1.Items.FindByValue(dropdownValue));

Posted in .NET 2.0 | 1 Comment »

Display all network printers

Posted by CJ on November 27, 2008

 

 

 

 

 

 

 

 

 

 

A post that I know I will need again.

string

strServer = \\\\printservername;

//if the computer is local machine, use the “.” instead
ConnectionOptions options = new ConnectionOptions();
options.Username =
“username”;
options.Password =
“pswd”;
options.Authority =
“NTLMDOMAIN:domain”; 

 

ManagementScope myScope = new ManagementScope(strServer + \\root\\cimv2, options);
SelectQuery oQuery = new SelectQuery(“SELECT * FROM WIN32_Printer”);
ManagementObjectSearcher oResults = new ManagementObjectSearcher(myScope, oQuery);

//Iterate through printers…
foreach (ManagementObject oItem in oResults.Get())
{
     string strPrinterName = oItem.Properties["DeviceID"].Value.ToString();
|

Posted in .NET 2.0 | Leave a Comment »

Where is GacUtil in Windows Server 2008 & VS2008

Posted by CJ on November 27, 2008

I regulary run Post Build events in Visual Studio on my development machines to install assemblies into the GAC immediatley after a successful build. This save me a lot of time.

However, have been working with Windows Server 2008 and Visual Studio 2008 and couldn’t find the GacUtil.exe in the usual spots on the file system … e.g C:\Program Files\Microsoft Visual Studio 9.0\SDK.

I finally found the location and it has been moved to C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin

So I can know put in my Post Build events like this:
“C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil.exe” -u “$(TargetName)”
“C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil.exe” -i “$(TargetPath)”

Posted in .NET 2.0 | Leave a Comment »