Saturday, September 12, 2009

Sharepoint WebService Deployment Routine

Follow the steps for deploying ASP.Net Webservices to Sharepoint environment.
1. Run the ASP.Net Webservice from Visual Studio (Hit F5).
2. Copy the URL from the browser.
3. Open Visual Studio Command Prompt.
4. Go any Folder using DOS Command
5. Type the Command DISCO http://servername:portnumber/WebServiceName.asmx ( URL Copied in Step 2)
6. This will generate the discovery (.disco) file and the WebService Definition (.wsdl) file to the Current Folder.
7. Rename the .disco and .wsdl to WebServiceNameDisco.aspx and WebServiceNameWsdl.aspx
8. Replace the header of the (files mentioned in Step 7) .aspx files to use ASPX page header tags
<%@ Page Language="C#" Inherits="System.Web.UI.Page" %> <%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint.Utilities" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
9. Replace the webservice url references inside the file to use Server tag which builds the Dynamic WebUrl at request time.
Remove the localhost link to the wsdl and asmx uri with
<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + "?wsdl"),Response.Output); %> for wsdl
and <% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> respectively
10. Open the .asmx file in some text editing tool (notepad for eg.) and replace the CodeBehind to use the Respective class and the Dll name space.
<%@ WebService Language="C#" Class="NameSpace.ClassName, NameSpace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=dllkeytoken" %>
where NameSpace is your dll namespace, ClassName is the WebService class name and dllkeytoken is the public ket token of dll. 11. Copy WebServiceName.asmx, WebServiceNameDisco.aspx and WebServiceNameWsdl.aspx to ISAPI Folder in the 12 Hive.
12. Test the WebService Request by typing the WebService Request as follows, http://sharepointurl/_vti_bin/WebServiceName.asmx.

Note: The WebService can be debugged in Visual Studio (if dll Deployed is in Debug Mode) by attaching it to the w3wp.exe process.

Monday, August 24, 2009

Setting up Sharepoint Server Search to index pdf content and to show PDF Icon

  1. Decide the image to be shown for the pdf doc icon and copy it to 12\TEMPLATE\IMAGES (Normally icpdf.gif file)
  2. Open DOCICON.XML which is located in folder 12\TEMPLATE\XML
    1. Under the node <byextension> add the below statement.
      1. <mapping key="pdf" value="imageFileName.gif">
      2. imageFileName.gif is the name of the gif file copied above
      3. Save the XML file.
  3. Go to Sharepoint Central Admin -> Shared Services
    1. Click on file types
      1. Click on the new file type to add the pdf file type. Click ok to add it to the list. And verify that the file extension is populated.
  4. Stop the IIS
  5. Install the Adobe IFilter which can be downloaded from internet (ifilter60.exe).
  6. After successful installation of Abode IFilter restart IIS.
  7. Reset Crawled content (SharedServices -> Search Settings) this is required since it may not re-crawl the older sites even in Full Crawl.
  8. Now need to add the Name column to do this follow the steps
    1. Go to Search Settings -> Metadata property mappings
    2. Add a new Mapped Property for FileLeafRef. Click on the Add Mapping, in the seach text box enter keyword fileleafref and click on find to filter the Select Crawled property to ows_FileLeafRef(Text). Click on ows_FileLeafRef(Text) in the list box to select it and Click OK. Enter the propery name as “Name”
    3. Click Ok to Save it.
    4. Make sure that the newly added property is populated in the list
  9. After Resetting go to Content Sources and Crawl Schedules
  10. Apply a Full Crawl
  11. Wait for the crawl to complete.
  12. Once the crawl is completed the pdf document matching the search criteria will be shown in search results.

Wednesday, August 12, 2009

Using Excel Service hosted using Sharepoint in .Net Application (C#)

An Excel Sheet is created to do a calculation of ADD.
Cell$G$155 is set to function SUM of the values on Cell$G$145 and Cell$G$150 (Instead of the Cell and Row No, the Defined a Name to the Cell and that can be used)
The Above excel is published to an Excel enabled Sharepoint Library.
The above library url has to be set as trusted Url in the Sharepoint Central Admin Excel Services Settings.
Below is how that published excel can be used for calculation from another application (webpart, Console or anyother .Net Application) using C#.
Add the Web Service Reference of the ExcelService first to the application.

ExcelService oExcelServ = new ExcelService();
oExcelServ.Url = SPContext.Current.Web.Url + "/_vti_bin/ExcelService.asmx";
oExcelServ.Credentials = System.Net.CredentialCache.DefaultCredentials;

Status[] Status = null;
String SessionID = null;
string pathWorkBook = @"http://servername/LibraryName/excelFile.xlsx";
SessionID = oExcelServ.OpenWorkbook(pathWorkBook, "en-US", "en-US", out Status);
int val1, val2;

//EXCELSHEETNAME à The Name of the Sheet in the .xlsx file which is published.
//EXCELSHEETNAME!$G$145 à SheetName!$CellAlphabet$RowNo
Status = oExcelServ.SetCellA1(SessionID, "EXCELSHEETNAME", "EXCELSHEETNAME!$G$145", val1);
Status = oExcelServ.SetCellA1(SessionID, "EXCELSHEETNAME", "EXCELSHEETNAME!$G$150", val2);

//Execute the CalculateWorkbook function to trigger Calculation
Status = oExcelServ.CalculateWorkbook(SessionID, CalculateType.CalculateFull);
object result = null;

// Read the result back from the Cell.
result = oExcelServ.GetCellA1(SessionID, "EXCELSHEETNAME", "EXCELSHEETNAME!$G$155", true, out Status);

Tuesday, August 4, 2009

Applying Theme to Login.aspx in Sharepoint

Ever wondered how to have the look and feel of Sharepoint login page based on the theme applied on site collection? I never thought about the importance of that until there was a site collection which had theme applied and forms based authentication enabled. The site was looking beautiful with the theme applied, application and layout pages were having the same look and feel, but when the sign in was clicked all went to the same sharepoint blue look and feel … hmmm it's not that good to see that blue color from a rich theme applied website isn't ?

Applying a theme will change the look and feel of pages which come from _layouts folder as well as the application pages. Login.aspx also resides under _layouts folder in the 12 Hive, but why it is not inheriting the theme?, this was the first question came in to my mind. So on investigating more in the login.aspx and its associated master page simple.master I found a workaround and that is as below.

  1. If the login.aspx is closely looked, we can see that it uses the simple.master page and it misses the tag to inherit the theme (<SharePoint:Theme runat="server"/>).
  2. A new master page named login.master was created by taking a copy of simple.master.
  3. Added the theme server tag under the head html tag.
    1. <HEAD runat="server">

      ….

      <SharePoint:Theme runat="server"/>

      ….

        </HEAD>

  1. Saved the login.master and copied it to LAYOUTS Folder.
  2. Updated the login.aspx to use the login.master.
    1. <%@ Page Language="C#" Inherits="Microsoft.SharePoint.ApplicationPages.LoginPage" MasterPageFile="~/_layouts/login.master" %>
  3. That's it. Go to IE and refresh the login page to see login page with theme applied.
  4. Enjoy !!

 

Monday, July 6, 2009

Modified by column value not coming in Sharepoint Search.

Problem: Sharepoint Search doesn't return Modified Column value during Search (Object Model as well)
Resolution: Follow the below steps

Search – Sharepoint Indexing Services should be running

Navigate to the Search Settings in Shared Services

Click on the Metadata property mappings

Find the property of name ModifiedBy

Click on the modifiedBy link to go to the Edit Managed Property page.

In the edit page click on the button Add Mapping

In the crawled property selction webpage dialogue which gets open when the add mapping button is clicked, Choose Office in the Select Category combo, to filter it based on Office.

And find the property Office:8(Text) from the properties list, need to select the first property only (Here we can find more than one property listed with same name) and Click OK button to select it.

Make sure the property got mapped (check this in the Mapping to crawled properties section).

Now go back to the Metadata property mappings and click on the Office:8(Text)link.

And verify the office:8 property mapped information

And make sure that Property Set ID is showing the same value as shown above, and it is mapped to the ModifiedBy managed property.

Go Back to the Search Settings

Start Full Crawl on the content source

And there you go !! Search should return you the Modified By value in results..

Cheers …!!