Archive for October, 2009

10/21/09
Fahad Zia

Changing SharePoint Page Titles


I was asked to change SharePoint page titles as most the pages made by the site contributors had “Page – pageurl” in it. For example if a page name “infomgt.aspx” was created with Title “Information Management” they would see “Pages – infomgt” in the title bar. They would like the users to be able to save pages in favourites with a meaningful name. Also other pages that were created using Article Page Layout were fine and were displaying the actual Title of the item and not the url.

So my first step was to look at the masterpage and this is what I saw:

<Title ID=onetidTitle><asp:ContentPlaceHolder id="PlaceHolderPageTitle" runat="server"/></Title>

ok then opened ArticleLeft.aspx and BlankWebPartPage.aspx using SharePoint Designer.
For title in ArticleLeft.aspx I saw:

<asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
	<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
</asp:Content>

and for BlankWebPartPage.aspx :

<asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
	<SharePointWebControls:ListProperty Property="Title" runat="server"/> - 
	<SharePointWebControls:ListItemProperty Property="BaseName" MaxLength=40 runat="server"/>
</asp:Content>

By comparing to the title “Pages – pageurl” I could tell that SharePointWebControls:ListProperty Property=”Title” was getting the list title and SharePointWebControls:ListItemProperty Property=”BaseName” the pageurl(minus the extension). To change it here is what my modified BlankWebPartPage.aspx title looks like:

<asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
	<SharePointWebControls:ListProperty Property="Title" runat="server"/> - 
	<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
</asp:Content>

this now shows the title as “Pages – Information Management”. Much easier to read. Of course this can be changed to anything you want.

10/19/09
Fahad Zia
tags:   ,

Uploaded jpg image not getting displayed in SharePoint


I was working on an upload image web part that would upload image to a SharePoint picture library. Strangely some of the pictures would get uploaded but when I would copy the URL to the image it will display as blank image as shown below:

blankimage

This did not make sense to me since when i would go to the picture library I could see the thumbnail and even the preview image EXCEPT the actual image. Spending more time on it I found out that the image that was not getting displayed had CMYK color profile which isn’t supported by browsers. Ok but why would it display as thumbnail and preview? The answer is when you upload image in SharePoint it optimizes and generates thumbnail and preview image on the fly so if you actually see the path of the thumbnail you will see “/t” and for preview you will see “/w” in the image src property.

Ok now that I know the image was CMYK how can I stop the user to upload CMYK or maybe convert it to RGB as SharePoint does? In my case I showed an error if they tried to upload CMYK image.

//=================================================================

public static string GetImageFlags(System.Drawing.Image MyImage)
{
   ImageFlags FlagVals = (ImageFlags)Enum.Parse(typeof(ImageFlags), MyImage.Flags.ToString());
   return FlagVals.ToString();
}

//=================================================================

public static bool IsCMYK(System.Drawing.Image MyImage)
{
   bool ReturnVal;
   if ((GetImageFlags(MyImage).IndexOf("Ycck") > -1) || (GetImageFlags(MyImage).IndexOf("Cmyk") > -1))
   {
    ReturnVal = true; 
   }
   else
   { 
     ReturnVal = false; 
   }
   return ReturnVal;
}

I got this code from: http://www.maxostudio.com/Tut_CS_CMYK.cfm. And then when user uploads image we can test it like this:

//CMYK color space not allowed
Bitmap bitmap = new Bitmap(fuPic.PostedFile.InputStream);
if (IsCMYK(bitmap))
{                    
  lblErr.Visible = true;
  lblErr.Text = "* CMYK color space not allowed. Please try again";
  return;
}