Kanithi's Professional Blog

December 31, 2009

Custom .NET Application integration to SharePoint

Filed under: MOSS 2007 — Veera Kanithi @ 3:07 pm

My thoughts on several integration levels of a custom .NET application to SharePoint…

  • Integration Level 0 (No Integration)

Advantages

  • Simplest solution as there is no need to integrate with MOSS 2007 or deploy.
  • More reliable as there is no reliance on MOSS 2007 services.
  • Server requirements are reduced as SharePoint services are not running/not required.
  • Simpler development and deployment model and debugging.
  • Regular workstations can be used for development and Visual Studio 2008 is good for development and no add-ons or extensions required.
  • Can take advantage of third party tools such as DevExpress and Log4net with little or no setup changes.
  • Service account can be used for database access, no need to worry about Single Sign On.

Disadvantages

  • Limited integration with existing MOSS 2007 portals.
  • Another hosting environment to maintain.
  • Cannot take advantage of list data that is available in MOSS 2007.
  • MasterPages and Login pages with common user controls must be developed.
  • Cannot take advantage of SharePoint security model
  • Integrating to MOSS 2010 will be another complete effort.

  

  • Integration Level 1 (Using ASP.NET 3.5 hosted inside MOSS 2007 as Application Pages)

Advantages

  • Simpler development Model compared to higher levels of integration and debugging the Business objects and data objects is possible.
  • SharePoint is aware of the page – so the link is natively visible to portals (i.e. the link doesn’t need to be added to SharePoint)
  • Can take advantage of SharePoint master page, so the look and fell will be consistent across the organization. This will fasten the development process as there is no need for login and other user controls.
  • Application can be developed in regular ASP .NET fashion and integrated into MOSS 2007 as application pages, so regular ASP .NET debugging can be leveraged.
  • Single hosting environment and other Windows 2003 web servers can be taken off
  • Can take advantage of SharePoint’s security model such as User Profile.
  • Can take advantage of some of SharePoint’s features for future development.
  • Can take advantage of collaboration with some existing list data.
  • Don’t have to concentrate as much as for regular .NET apps regarding the AppScan vulnerabilities
  • Can take advantage of .Net 3.5 features such as ADO .NET entity framework and LINQ compared to higher levels of integration
  • Since each page is independent of other, MOSS 2010 migration will be easier compared to higher levels of integration.
  • Can take advantage of MOSS features in application enhancements.

Disadvantages

  • Dependency upon MOSS.
  • More powerful servers are required as there will be single hosting environment that process both regular SharePoint information and ASP .NET web application.
  • Initial setup of integrating ASP .NET web app into MOSS 2007 could be a night mare as there are some configuration changes, master file changes and some code changes to integrate the custom.master file.
  • May find some difficulties working with some third party controls such as Dev Express.
  • May find some challenges in using open source utilities such as Log4net and Microsoft Data Access Applications blocks as MOSS 2007 requires the signed assembly.
  • Changes in development and deployment process as there will be integration and that needs to be done on a web server which has SharePoint installed.
  • Verbose logging should be enabled in order to track down the errors in the integration part.
  • Double hop issue, must use local db account to access the DB or configure Single Sign On.
  • Cannot use proper identity impersonate with SharePoint security model.

  

  • Integration Level 2 (Using ASP.NET 3.5 and developing inside MOSS 2007)

Advantages

  • Single hosting environment.
  • Can take advantage of full SharePoint’s security model.
  • Can take advantage of SharePoint’s rich controls such as SPGridView, built-in web parts and Workflows.
  • Can integrate with existing list data if any.
  • Can take advantages of MOSS 2010 easy development framework such as BCS.

Disadvantages

  • Dependency upon MOSS 2007.
  • Site Pages render slower in MOSS 2007.
  • There is reliance on more components – so reliability of system is lower.
  • More powerful servers are required as there will be single hosting environment that process both regular SharePoint information and ASP .NET web application.
  • May find some difficulties working with some third party controls such as Dev Express.
  • May find some challenges in using open source utilities such as Log4net and Microsoft Data Access Applications blocks as MOSS 2007 requires the signed assembly.
  • Difficulty in troubleshooting. There are different log files to search for the error and it’s not clear where to look.
  • Development environment issues could arise as work stations do not have SharePoint libraries installed.
  • Reduced ability to use new .NET 3.5 features such as ADO .NET entity framework and LINQ.
  • Oracle client must be installed on the server in order to connect to Oracle db
  • More effort in migrating to MOSS 2010 compared to Integration Level 1.

  

  • Integration Level 3 (Deep Integration with MOSS 2007 using Lists , Business Data Catalog and Data Sources)

Advantages

  • Single hosting environment.
  • Can take full advantage of SharePoint’s security model.
  • Can take advantage of SharePoint’s rich controls such as SPGridView, built-in web parts and Workflows.
  • Can leverage current look and feel of SharePoint sites if they already exist.
  • Lists are easily customized by users.
  • Notifications when data changes.
  • Can take advantages of MOSS 2010 easy development framework such as BCS.

Disadvantages

  • Complete revamp of business process flow and this will require significant user education.
  • Dependency upon MOSS 2007.
  • Site Pages render slower in MOSS 2007.
  • There is reliance on more components – so reliability of system is lower.
  • More powerful web servers and SQL server required.
  • Difficulty in troubleshooting. There are different log files to search for the error and it’s not clear where to look.
  • Performance and scalability issues using Business Data Catalog to connect to external data sources.
  • Insane Development Requirements: You must have a Windows 2003/2008 Server as your Workstation; you really should be local Administrator on it.
  • More effort in migrating to MOSS 2010 compared to other Integration Levels. 

December 16, 2009

Basic and quick steps to configure log4net in .NET application

Filed under: .NET — Veera Kanithi @ 9:33 pm

1. Download the latest copy of log4net from Apache, at this point of time the available version is 1.2.10. Link: http://logging.apache.org/log4net/download.html

2. Take the log4net.dll from the location log4net-1.2.10\bin\net\2.0\release and add it as a reference in your .Net project

3. Change the Web.config or App.config file for log4net settings as below.

Add “<section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler,log4net”/>” under “configSections” tag

Create a new log4net section preferably before <system.web> and it will contain appenders and logger details as below.

<log4net>

       <!—SQL Server appender –>

    <appender name=”AdoNetAppender” type=”log4net.Appender.AdoNetAppender”>

      <bufferSize value=”1″ /> <!—Always use low buffer value for AdoNetAppenders–>

      <connectionType value=”System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ />

      <connectionString value=”data source=[database server];initial catalog=[database name];integrated security=false;persist security info=True;User ID=[user];Password=[password]” />     

      <commandText value=”INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)” />

      <parameter>

        <parameterName value=”@log_date” />

        <dbType value=”DateTime” />

        <layout type=”log4net.Layout.RawTimeStampLayout” />

      </parameter>

      <parameter>

        <parameterName value=”@thread” />

        <dbType value=”String” />

        <size value=”255″ />

        <layout type=”log4net.Layout.PatternLayout”>

          <conversionPattern value=”%thread” />

        </layout>

      </parameter>

      <parameter>

        <parameterName value=”@log_level” />

        <dbType value=”String” />

        <size value=”50″ />

        <layout type=”log4net.Layout.PatternLayout”>

          <conversionPattern value=”%level” />

        </layout>

      </parameter>

      <parameter>

        <parameterName value=”@logger” />

        <dbType value=”String” />

        <size value=”255″ />

        <layout type=”log4net.Layout.PatternLayout”>

          <conversionPattern value=”%logger” />

        </layout>

      </parameter>

      <parameter>

        <parameterName value=”@message” />

        <dbType value=”String” />

        <size value=”4000″ />

        <layout type=”log4net.Layout.PatternLayout”>

          <conversionPattern value=”%message” />

        </layout>

      </parameter>

      <parameter>

        <parameterName value=”@exception” />

        <dbType value=”String” />

        <size value=”2000″ />

        <layout type=”log4net.Layout.ExceptionLayout” />

      </parameter>

    </appender>

 

      <!—File Appender –>

    <appender name=”RollingFileAppender” type=”log4net.Appender.RollingFileAppender”>

      <param name=”File” value=”C:\\temp\\log4net.log” />

      <param name=”AppendToFile” value=”true” />

      <param name=”MaxSizeRollBackups” value=”10″ />

      <param name=”MaximumFileSize” value=”1000″ />

      <param name=”RollingStyle” value=”Size” />

      <param name=”StaticLogFileName” value=”true” />

      <layout type=”log4net.Layout.PatternLayout”>

        <param name=”ConversionPattern” value=”%d [%t] %-5p %-45c [%x] – %m%n” />

      </layout>

    </appender>

    <root>

      <level value=”ALL” />

      <appender-ref ref=”RollingFileAppender” />     

    </root>

    <logger name=”WebForm1″>

      <level value=”INFO” />

      <appender-ref ref=”RollingFileAppender” />

    </logger>

</log4net>

As you can see, we can have several types of Appenders, I have included only 2 appenders. You can configure any number of appenders in the web.config file and can always switch back and forth with appender-ref tag.

Before using the AdoNetAppender, we should create a table in the SQL Server which the appender pointing to with the structure below.

CREATE TABLE [dbo].[Log] (

    [Id] [int] IDENTITY (1, 1) NOT NULL,

    [Date] [datetime] NOT NULL,

    [Thread] [varchar] (255) NOT NULL,

    [Level] [varchar] (50) NOT NULL,

    [Logger] [varchar] (255) NOT NULL,

    [Message] [varchar] (4000) NOT NULL,

    [Exception] [varchar] (2000) NULL

)

4. Add the following attribute to the AssemblyInfo file

[assembly: log4net.Config.DOMConfigurator()]

5. We are almost done, declare log object using ILog interface where ever you want to put the custom logging in the code and enter the messages using INFO, DEBUG, ERROR logger levels. More details about the logger levels can be found from Apache site

private static readonly log4net.ILog log = log4net.LogManager.GetLogger(“WebForm1”); //WebForm1 is the class name which should match with the logger name in the web.config file

log.Info(“Hi There.”);

6. Open the log file or SQL Server according to the appender and check logging information. Sample should look like this.

2009-12-16 15:57:28,534 [4] INFO  WebForm1                                   [(null)] – Hi There.

Note: the latest version of log4net.dll will work with both Visual Studio 2005 and Visual Studio 2008

Note: Apache has a patch for AdoNetAppender to support connectionStrings configuration section from web.config, details: http://issues.apache.org/jira/browse/LOG4NET-88

December 11, 2009

Use “Save As” any email attachment or Document to SharePoint List

Filed under: MOSS 2007 — Veera Kanithi @ 3:50 pm

Your best bet is to add the SharePoint library as a Network location in your Windows Explorer. In windows explorer, right click on Computer –> Add Network Connection –> Add custom location (use the SharePoint library url). This allows you to use “save as” from any of your desktop applications (including Outlook and browser) to select your SharePoint library as well as using “Attach File” in an Outlook email to select files from the SharePoint library. This would also eliminate the need to have SharePoint open.

Explorer view of the SharePoint Library

Filed under: MOSS 2007 — Veera Kanithi @ 3:49 pm

You can also use the explorer view of the SharePoint Library (Library Name–>Actions–>Windows Explorer View) to drag&drop/copy&paste email (or just the attachments) and files from Outlook and your desktop. You can also sync this library back to Oultook so you can browse it from Outlook. Or for sending out files, while in Explorer view, mouse right click on one or more files, select “Sent To..”–>Mail Recipient. It would be great if SharePoint had that option under it’s Send to, but that is a third party add-on right now.

Drag your Outlook file attachment directly into Sharepoint

Filed under: MOSS 2007 — Veera Kanithi @ 3:49 pm

Did you know that you can drag your Outlook file attachment directly into Sharepoint?

It is straightforward with a few exceptions. Here are the steps:

Open your SharePoint site
Select the Document Library to store the file
Select the “Explorer View” of the Document Library
Now open Outlook
Open the Email with the attachment
Resize Outlook so you can see the explorer view of the document library

Click on the attachment and drag to the folder area of the explorer view

The beauty of this is that the file never gets pulled out of Outlook onto a local drive/directory and is less likely to present a security risk.

How to use SharePoint Log Files

Filed under: MOSS 2007 — Veera Kanithi @ 3:15 pm
Purpose: SharePoint has a new logging architecture that gives you a much better way of determining issues with your SharePoint farm.
Result: Know how to find and read the SharePoint log files
Task 1 – Turn on verbose and information logging

  • Open the Central Administration Console
  • Click “Operations” tab
  • Under “Logging and Reporting”, click “Diagnostic Logging”

          

  • For “Select a category”, select “All”
  • Under “Least critical event to report to the event log”, select “Information”
  • Under “Least critical event to report to trace log”, select “Verbose”

            

  • Click “Ok”

Task 2 – Review the log file

  • Open the 12 hive Logs directory (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS)
  • Find the newest log file and open it
  • Open Microsoft Excel 2007
  • Copy and paste the data from the log file into Excel
  • In the menu, click “Data”
  • In the ribbon, under the “Sort & Filter” jewel, click “Filter”

             

  • A majority of your errors will revolve around the w3wp processes, therefore in the second column (process), click the filter dropdown
  • Uncheck “Select All”
  • Check all the w3wp.exe processes

            

  • Click “Ok”
  • Review the entries that are present, when any exception occurs across SharePoint it will show up here!
Exercise #2 – Log to SharePoint Log File
Purpose: Learn to append your own messages to the log file
Result: Log entries in the Log files
Task 1 – Create a console application

  1. Open Visual Studio 2005
  2. Create a new console application
    • Click File->New->Project
    • Select Console Application
    • For location, type “D:\Lab Work”
    • For name, type “Logger”
    • Click Ok
  3. Add a reference to Microsoft.Office.Server.dll
    • Right click the project, select “Add Reference”
    • Click the Browse tab
    • Browse to c:\program files\common files\microsoft shared\web server extenstions\12\isapi
    • Select Microsoft.Office.Server.dll
    • Click Ok
  4. Update the Main code to the following:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Office.Server;
    namespace ConsoleApplication2
    {
    class Program
    {
    static void Main(string[] args)
    {
    try
    {
    throw new Exception(“Something bad happend”);
    }
    catch (Exception ex)
    {
    Microsoft.Office.Server.Diagnostics.PortalLog.LogString(“This was a bad one…”, null);
    }
    }
    }
    }
  5. Run the application
  6. Open the log files, find your log entry

            

Fully Customizable GridView

Filed under: .NET — Veera Kanithi @ 2:41 pm

Need a fully customizable (Nested, Editable, Sortable, etc ) GridView.

Check my article below…

http://www.codeproject.com/KB/webforms/EditNestedGridView.aspx

Blog at WordPress.com.