Wednesday, June 4, 2008

Creating PDF documents using Microsoft Office Add-in

Wondering how to programatically create PDF! Here is the C# code for you guys!


using Microsoft.Office;
using Microsoft.Office.Core;
using Microsoft.Office.Interop;

object sE = Type.Missing;
object sPDFFile = @"C:\sPDFFile.PDF";
object sDOCXFile = @"C:\1.docx";
object wdFormatPDF = 17; // 17 PDF format.
object WdDoNotSaveChanges = 0;
Microsoft.Office.Interop.Word.Application wdo = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Documents wdocs = wdo.Documents;

//Open the Document
Microsoft.Office.Interop.Word.Document wdoc = wdocs.Open(ref sDOCXFile, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE);

//Save the Document
wdoc.SaveAs(ref sPDFFile, ref wdFormatPDF, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE, ref sE);

//Little CleanUp
wdoc.Close(ref WdDoNotSaveChanges, ref sE, ref sE);
wdo.Quit(ref WdDoNotSaveChanges, ref sE, ref sE);

Requirements:
Download 2007 Microsoft Office Add-in: Microsoft Save as PDF and XPS from below link
http://download.microsoft.com/download/b/5/3/b5370004-d59d-493f-b005-2299ffca8596/SaveAsPDF.exe

Thursday, March 27, 2008

Working on Dev Machine And Not Installed with SharePoint (Workaround for Workstation Development!)

Copy few DLL's and register them and you all set for MOSS Workflow devlopment.
  1. Copy all the server DLL’s from this location “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI” to Dev Machine Maintain the same file structure.
  2. Then GAC these DLL’s (Drag N Drop into “C:\WINDOWS\assembly”)
    a. Microsoft.SharePoint.dll
    b. Microsoft.SharePoint.Security.dll
    c. Microsoft.Sharepoint.WorkflowActions.dll
    d. Microsoft.Office.Workflow.Tasks.dll
  3. Copy "microsoft.sharepoint.WorkflowActions.intl.dll" from Server by navigating through
    C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SharePoint.WorkflowActions.intl\12.0.0.0__71e9bce111e9429c
    COPY microsoft.sharepoint.WorkflowActions.intl.dll to Dev Machine
    3.a Now GAC the above DLL into your Dev Machine.
  4. Copy " microsoft.SharePoint.workflowactions.intl.resources.dll" from Server by navigating through C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SharePoint.WorkflowActions.intl.resources\12.0.0.0__71e9bce111e9429c
    COPY microsoft.SharePoint.workflowactions.intl.resources.dll to Dev Machine
    4.a Now GAC the above DLL into your Dev Machine
  5. Copy "microsoft.sharepoint.library.dll" from Server by navigating through C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SharePoint.Library\12.0.0.0__71e9bce111e9429c
    COPY microsoft.sharepoint.library.dll to Dev Machine
    5.a Now GAC the above DLL into your Dev Machine.
  6. Install Visual Studio 2005 Extensions for Windows Workflow Foundation (EN)
  7. If you wish you can also install “Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System_Setup"

Now you all set for developing SharePoint Workflows!

Tuesday, March 18, 2008

Assigned item level permission (Moss 2007)

Currently working on a new project which requires WF auto assign the permission at document level once this document finish with all the Approvals.

Console App sample Code for you to test:

static void Main(string[] args)
{
string strResult = "";
string strFileID = "1";
try
{
SPSite WebApp = new SPSite("http://security/");
SPWeb Site = WebApp.OpenWeb();
SPList list = Site.Lists["Documents for Review"];
SPQuery newSPQuery = new SPQuery();
newSPQuery.Query = "" + strFileID + "";

SPListItemCollection listItemCol = list.GetItems(newSPQuery);
if (listItemCol.Count > 0)
{
foreach (SPListItem item in listItemCol)
{
SPRoleDefinition RoleDefinition = Site.RoleDefinitions.GetByType(SPRoleType.Reader);
SPRoleAssignment RoleAssignment = new SPRoleAssignment("us\\MOSSUser, "rajasudhakar@shotmail.com", "Raja Dandu", "Test via Code notes");
RoleAssignment.RoleDefinitionBindings.Add(RoleDefinition);

if (!item.HasUniqueRoleAssignments)
{
item.BreakRoleInheritance(true);
}
item.RoleAssignments.Add(RoleAssignment);
item.Update();
}
}
}
catch (Exception ex)
{
strResult += "Permission not set, reason: " + ex.Message;
}


Related links:
http://msdn2.microsoft.com/en-us/library/ms414036.aspx
http://msdn2.microsoft.com/en-us/library/ms414400.aspx
http://office.microsoft.com/en-us/sharepointtechnology/CH100649861033.aspx

Monday, January 7, 2008

PublicKey attribute in '.NET Framework 2.0' doesn't match…

It’s seems that when Microsoft published Microsoft Visual Studio 2005 Tools for Office Second Edition Runtime
The redistribution was signed with new certificate, hence the Public Key Changed.

We have two options for now
1. Continue to use the same version of the runtime:
Since IDE prompt for Warning, we can ignore warnings while building the package.
2. Upgrade the bootstrapper package from RTM ver to SE version:
Download the SE ver of runtime from Microsoft Link http://www.microsoft.com/downloads/details.aspx?FamilyID=4468D8CB-B43E-4B09-82F6-8BA3F7B5E935&DisplayLang=en
And fallow the Additional Information on the page.

Thursday, December 27, 2007

Tuesday, December 25, 2007

Visual Studio VS SharePoint Designer

A few basic differences between these two amazing development tools
Visual Studio             ==> VS
SharePoint Designer  ==> SPD

  1. Code Behind
          Yes (VS)
          No (SPD)

  2. Development Model
          Graphical Designer (VS)
          Wizard Based (SPD)

  3. Supported WF Hosts
          WSS/MOSS/Others (VS)
          WSS/MOSS (SPD)

  4. Type of WF Supported
          Sequential & State Machine (VS)
          Sequential (SPD)

  5. Activities
          Built-in, Use & Dev Custom (VS)
          Built-In & Use Custom (SPD)

  6. Form Technology
          Design forms in any technology Including
          ASP.NET/InfoPath (VS)
          Auto generated, customizable ASP.NET Forms (SPD)

  7. Modification
          Can modify WF (VS)
          Can’t modify WF using modification forms (SPD)

  8. Association
          Can be associated with multiple content types,
          list and document libraries (VS)
          Associated automatically with a single list at design time,
          No other association possible (SPD)

  9. Debugging
          Yes
          No (SPD)

  10. Deployment
          Must build package & Deploy WF using SharePoint Feature
          technology (VS)
          Automatically Deployed to associated list,
          live Changes (SPD)

Tuesday, December 4, 2007

Setting Up Kerberos For MOSS 2007 Server

1. Configure Service Principle Names (SPN)
The first thing we need to do in order to enable Kerberos for SharePoint is configure Service Principle Names (SPNs) for our SharePoint service accounts (US\Srv_Moss2007) in Active Directory

SPNs are used by Kerberos to ensure that only certain accounts have permission to delegate a specific service on a user's behalf. An SPN needs to be configured for each service and address that the account needs to delegate for. SPNs are configured by using SetSPN.exe

Example for tester22 site:
Setspn –A HTTP/tester22.us.domain.net US\srv_moss2007
Setspn –A HTTP/tester22 US\srv_moss2007

Note: Remove away all the SPN for local host Trust for Delegation
In addition to setting the SPNs for each of your service accounts, you also need to trust each of the computer accounts and some of the service accounts for delegation.

2. Trusting for delegation means that the accounts are allowed to delegate on a user's behalf.
In order to trust for delegation you need to open Active Directory Users and Computers as a user with domain administration rights and follow these instructions

Process the following for “US\Srv_Moss2007”

Locate the account and click 'properties'
Navigate to the 'Delegation' tab
Choose 'Trust this user/computer for delegation to any service (Kerberos)'

3. Enable Kerberos on your web applications
In MOSS 2007, the switch between Kerberos and NTLM is very simple and is undertaken via Central Administration.

If you are creating your farm from scratch, be sure to set Central Administration itself to use Kerberos which you can set as part of the 'SharePoint Products and Technologies Configuration Wizard', however if the farm is pre-created you can easily enable Kerberos by following these steps:

Open Central Administration
Navigation to Application Management > Authentication Providers
Choose the web application you wish to configure from the drop-down in the top right corner (this includes the Central Administration web application)
Click on 'Default'
Set the authentication to Negotiate (Kerberos)
IISRESET

4. Enable Kerberos on your SSP
In this step you enable Kerberos on your SSP. Follow these steps:
Open Central Administration
Navigation to Application Management > Authentication Providers
Choose Web Application
Click on Zone Default
Under Edit Authentication, Section Integrated Windows authentication
Choose Negotiate (Kerberos)
Save and Close

5. Component Services Configuration
We need to set various permissions in Component Services. Follow these steps:

Open Component Services on the MOSS server
Navigation to Component Services > Computers > My Computer
Click on Properties (for My Computer) > Default Properties > Default Impersonation Level = Delegate
Navigate to Component Services > Computers > My Computer > DCOM Config > IIS WAMREG Admin Service
Click on Properties (for IIS WAMREG Admin Service) and navigate to the Security tab
Edit Launch and Activate Permissions
Grant all three of your application pool account 'Local Activation' permissions.

Example:
US\MySiteAppPool
US\SSPAdminAppPool
US\PortalAppPool

6. Troubleshooting Kerberos
Issue these commands and retest

A. KList purge
In the Server as well as testing workstation issue the fallowing command to clear the Kerberos tickets
KList purge
Then answer with flag Y (yes)

B. DNS & NetBIOS State
Issue fallowing command on server as well as workstation
Nbtstat –R
Ipconfig /flushdns