How to find a SharePoint Desinger’s designed page?
15 September 09 08:04 PM

By default SharePoint pages are ghosted pages, store their content in the content database but for the look & feel  and layouts they referred to file system pages ( master pages, css, user controls etc..).If you modify any page in SharePoint Designer then if will become un-ghosted pages. All the data related to this page will get stored in the database. Any modification you do to the look and feel of this page will not be affected on the complete site.

 

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace GhostFinder
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args == null || args.Length < 1)
            {
                PrintUsage();
                return;
            }

            bool hasUrl = false;
            string url = null;
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-url" && i + 1 < args.Length)
                {
                    url = args[i + 1];
                    hasUrl = true;
                }
            }

            if (!hasUrl)
            {
                PrintUsage();
                return;
            }

            using (SPSite site = new SPSite(url))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPFile file = web.GetFile(url);
                    if (file == null)
                    {
                        Console.WriteLine(string.Format("File '{0}' not found.", url), url);
                    }
                    else
                    {
                        SPCustomizedPageStatus page = file.CustomizedPageStatus;
                        Console.WriteLine("Status : " + page.ToString());
                    }
                }

            }
        }

        private static void PrintUsage()
        {
            Console.WriteLine(@"This is command line tool.");
            Console.WriteLine(@"Usage: To know customized page status, please provide the full page address i.e : -url [http://navdeepm1/sites/TeamSite/default.aspx]");
        }
    }
}

Postedby Navdeep Madan | 0 Comments    
How to delete OOB Announcements list from the SharePoint Site ?
11 September 09 12:03 AM

Announcements list template in SharePoint is installed as a feature with feature id 00bfea71-d1ce-42de-9c63-a44004ce0104. If you run the following command, the announcements section will get eloped from "Communications" section

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN>stsdm -o deactivatefeature -id 00bfea71-d1ce-42de-9c63-a44004ce0104 -url "http://brs2r04-16:7000/sites/TestSite"

clip_image002

If you would like to bring it back , then you need to run the command stsadm command with activate feature :-

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN>sts

dm -o deactivatefeature -id 00bfea71-d1ce-42de-9c63-a44004ce0104 -url "http://brs2r04-16:7000/sites/TestSite"

clip_image004

Here are the feature IDs of other List Templates :-

Libraries

Feature ID

List Template

Document Library

00bfea71-e717-4e80-aa17-d0c71b360101

101

Form Library

00bfea71-1e1d-4562-b56a-f05371bb0115

115

Wiki Page Library

00bfea71-c796-4402-9f2f-0eb9a6e71b18

119

Picture Library

00bfea71-52d4-45b3-b544-b1c71b620109

109

Data Connection Library

00bfea71-dbd7-4f72-b8cb-da7ac0440130

130

Translation Management Library

29d85c25-170c-4df9-a641-12db0b9d4130

1300

Slide Library

0be49fe9-9bc9-409d-abf9-702753bd878d

2100

Report Library

2510d73f-7109-4ccc-8a1c-314894deeb3a

433

Communications

Feature ID

List Template

Announcements

00bfea71-d1ce-42de-9c63-a44004ce0104

104

Contacts

00bfea71-7e6d-4186-9ba8-c047ac750105

105

Discussion Board

00bfea71-6a49-43fa-b535-d15c05500108

108

Tracking

Feature ID

List Template

Links

00bfea71-2062-426c-90bf-714c59600103

103

Calendar

00bfea71-ec85-4903-972d-ebe475780106

106

Tasks

00bfea71-a83e-497e-9ba0-7a5c597d0107

107

Project Tasks

00bfea71-513d-4ca0-96c2-6a47775c0119

150

Issue tracking

00bfea71-5932-4f9c-ad71-1557e5751100

1100

Survey

00bfea71-eb8a-40b1-80c7-506be7590102

102

Custom Lists

Feature ID

List Template

Custom List

00bfea71-de22-43b2-a848-c05709900100

100

Custom List in Datasheet View

00bfea71-3a1d-41d3-a0ee-651d11570120

120

Language and Translators

29d85c25-170c-4df9-a641-12db0b9d4130

1301

KPI List

065c78be-5231-477e-a972-14177cc5b3c7

432

Import Spread Sheet

   

Postedby Navdeep Madan | 1 Comments    
The following error was encountered while attempting to save the Page: Save operation failed with the following exception : Invalid item data -- missing FileRef
03 June 09 03:00 PM

RESOLUTION/WORKAROUND:

==========================

Replace the Page directive with the following statement.

<%@ Page language="C#" MasterPageFile="~masterurl/custom.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document" %>

STEPS TO REPRO:

====================

1. Create cutom search Page and add the following Page directive

<%@ Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>

2. Install it as a feature.

3. Add any advanced search Web Part on this Page and Change any property in edit mode of the page.

4. Nivigate to another Page in the site. An alert message will pops-up to store the page changes.

4. After you press the ok button, you will see the following error.

"The following error was encountered while attempting to save the Page: Save operation failed with the following exception : Invalid item data -- missing FileRef."

Postedby Navdeep Madan | 1 Comments    
Render the all the column of links list through BaseFieldControl.
27 May 09 10:06 PM

you need to set the "ItemContext" and "RenderContext" of the BaseFieldControl. If you create a SPContext only onetime,  assign to BaseFieldControl's "ItemContext" and "RenderContext" properties. First time when you add a webPart it a page, you will get all the control are rendering perfectly and providing you the correct data. But if you add the second instance of the same WebPart, the data of Links and Notes column are not comming repeating by the last row of the list. If you debug in the Visual Studio, you will get the error message "Operation is not valid due to the current state of the object"

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace ApplicationPages
{
    public class ControlTesterWebPart : WebPart
    {
        private SPList linksList;

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            this.GetListInstance();
            this.BuildTable();
        }

        private void BuildTable()
        {
            HtmlTable table = new HtmlTable();
            HtmlTableRow row = null;
            HtmlTableCell fieldNameCell = null;
            HtmlTableCell fieldValueCell = null;
            SPField field = null;
            BaseFieldControl fieldControl = null;
            LiteralControl fieldValueControl = null;

            foreach (SPListItem linkItem in this.linksList.Items)
            {
                foreach (string fieldName in this.linksList.DefaultView.ViewFields)
                {
                    // Makle a new row
                    row = new HtmlTableRow();

                    // Get the SPField instance
                    field = linkItem.Fields.GetField(fieldName);
                    // Field Name
                    fieldNameCell = new HtmlTableCell();
                    fieldNameCell.InnerHtml = string.Format("{0}:&nbsp&nbsp", field.Title);
                    row.Cells.Add(fieldNameCell);

                    // Field Value
                    fieldValueCell = new HtmlTableCell();
                    fieldControl = field.FieldRenderingControl;
                    fieldControl.ID = Guid.NewGuid().ToString();
                    fieldControl.FieldName = field.InternalName;
                    fieldControl.ListId = this.linksList.ID;
                    fieldControl.ItemId = linkItem.ID;
                    fieldControl.ControlMode = SPControlMode.Display;
                    SPSite site = new SPSite(SPContext.Current.Site.ID);
                    SPWeb web = site.OpenWeb();
                    SPContext Context = SPContext.GetContext(HttpContext.Current, linkItem.ID, this.linksList.ID, web);
                    fieldControl.ItemContext = Context;
                    fieldControl.RenderContext = Context;
                    fieldValueControl = new LiteralControl(fieldControl.GetDesignTimeHtml());
                    fieldValueCell.Controls.Add(fieldValueControl);
                    row.Cells.Add(fieldValueCell);
                    if (web != null)
                        web.Dispose();

                    // Add the row to the table
                    table.Rows.Add(row);
                }

Postedby Navdeep Madan | 1 Comments    
How to redirect on new Page at Item Deleting in SharePoint ECB Menu?
27 May 09 09:33 PM

1.    Create a feature to add the custom menu in the Feature and set the redirection to your custom Page. Create a feature.xml to add it as a feature.
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
                <CustomAction
                                Id="UserInterfaceLightUp.ECBItemToolbar"
                                RegistrationType="List"
                                RegistrationId="101"
                                Location="EditControlBlock"
                                Sequence="106"
                                Title="MY ECB DELETE ITEM">
                                <UrlAction Url=”/_layouts/DeleteItem.aspx?ListId={ListId}&amp;ItemId={ItemId}"/>
                </CustomAction>
</Elements>

2.    Create the DeleteItem.aspx and add the functionality to delete the List Item.

DELETEING THE ECB MENU
====================

The ECB menu item are rendered by the javascript file CORE.JS. By modifying the respective functions in this javascript file you can hide the ECB menu item from the item level menus. Modifying the CORE.JS file is not supported so it’s always recommended to create the custom core.js file and render it through the custom master page. The following are the steps to create a custom core.js file and render it through the custom master page

1. Copy the core.js file from C:\program files\common files\Microsoft shared\web server extensions\12\Template\layouts\1033 and copy it to the same folder with the name customcore.js. Make the respective changes in the customcore.js file.
2. Copy the default.master page and create the custom master page as custom.master.

3. In the custom master page Add the following line to render the core2.js file

<SharePoint:ScriptLink language="javascript" name="core.js" Defer="true" runat="server"/>
<SharePoint:ScriptLink language="javascript" name="customcore.js" Defer="true" runat="server"/>

4. Save the custom.master page and upload it to the master pages gallery of the site. Apply the custom.master page as the default master page for the site.

Postedby Navdeep Madan | 1 Comments    
Upgrade issue from SPS2003 to MOSS2007
13 September 08 08:53 AM

When you upgrade your SharePoint environment from SPS2003 to MOSS 2007 and if you have a “General Discussion” list, you will getnullin the “Last updated” field because is SPS2003 there is no such field named “Last Updated” exists.  You will get “Modified” in field “General Discussion” List of the older version of SharePoint.  If you add a new item in the list, you will get the latest values in both the column. So if you would like to replaceLast Updatedcolumn values with Modifiedvalues, you can use the following code:-

 

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Text;
   4:  using Microsoft.SharePoint;
   5:   
   6:  namespace UpdateDiscussionListColumn
   7:  {
   8:      class Program
   9:      {
  10:          static void Main(string[] args)
  11:          {
  12:              Console.WriteLine("Enter your SharePoint site URL :");
  13:              string strUrl = Console.ReadLine();
  14:   
  15:              Console.WriteLine("Enter your Discussion List name :");
  16:              string strDListName = Console.ReadLine();
  17:   
  18:              SPSecurity.RunWithElevatedPrivileges(delegate()
  19:              {
  20:                  using (SPSite oSite = new SPSite(strUrl))
  21:                  {
  22:                      using (SPWeb oWeb = oSite.OpenWeb())
  23:                      {
  24:                          SPList oList = oWeb.Lists[strDListName];
  25:   
  26:                          foreach (SPListItem oItem in oList.Folders)
  27:                          {
  28:                            
  29:                              if(oItem["Last Updated"] == null)
  30:                              {
  31:                                Console.WriteLine("old values");
  32:                                oItem["Last Updated"] = oItem["Modified"];
  33:                                oItem.Update();
  34:                                Console.WriteLine("New values" + oItem["Last Updated"].ToString());
  35:                              }
  36:                          }
  37:                          oList.Update();
  38:                      }
  39:                  }
  40:              });
  41:   
  42:              Console.WriteLine("Operation completed successfully");
  43:              Console.ReadLine();
  44:   
  45:          }
  46:      }
  47:  }
Postedby Navdeep Madan | 1 Comments    
Exporting Excel data to SharePoint 64 bit's List environment.
08 September 08 02:11 PM

If you are creating the windows application to export the data from Excel 2003 files to MOSS 64 bit environment, the following solution will help to achieve this functionality. we have to adopt this approach because till now there is no 64 bit version of the Microsoft.JET.OLEDB.4.0 driver available. So If you compile you assembly by choosing the "Any CPU" option in Visual Studio for windows application, you will not be able to connect and read the data from 32 bit of "Microsoft.JET.OLEDB.4.0" drivers. First create a custom web service in SharePoint, which add the reference of 64 bit API to export the data to SharePoint's List. Choose the Compilation options of "Any CPU"

   1:   
   2:  using System;
   3:  using System.Web;
   4:  using System.Web.Services;
   5:  using System.Web.Services.Protocols;
   6:  using System.Collections.Generic;
   7:  using System.Collections;
   8:  using Microsoft.SharePoint;
   9:  using System.Data;
  10:   
  11:  namespace ServiceLogic
  12:  {
  13:      [WebService(Namespace = "http://tempuri.org/")]
  14:      [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  15:      public class Service : System.Web.Services.WebService
  16:      {
  17:          public Service()
  18:          {
  19:   
  20:              //Uncomment the following line if using designed components 
  21:              //InitializeComponent(); 
  22:          }
  23:   
  24:          [WebMethod]
  25:          public string UpdateList(DataSet dataSet)
  26:          {
  27:              
  28:              using (SPSite site = new SPSite("http://blr3r07-19c:5794/sites/TestSite"))
  29:              {
  30:                  using (SPWeb web = site.OpenWeb())
  31:                  {
  32:                      SPList list = web.Lists["test"];
  33:                      SPListItem listItem = list.Items.Add();
  34:                      listItem["Title"] = dataSet.Tables[0].Rows[0][0].ToString();
  35:                      listItem.Update();
  36:                      return "Data Inserted";
  37:                  }
  38:              }
  39:          }
  40:   
  41:      }
  42:  }

 

Once you completed with programming & installation of your custom web service in you SharePoint 64 bit environment, move towards your exporting utility. Create a windows or console project in visual studio, which ever you like, I choose windows application. Add the web reference of your custom web service. Use the Microsoft.JET.OLEDB.4.0 to read the excel data and rapped it in a DataSet then pass to your SharePoint custom web service's web method.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.ComponentModel;
   4:  using System.Data;
   5:  using System.Drawing;
   6:  using System.Text;
   7:  using System.Windows.Forms;
   8:  using System.Data.OleDb;
   9:   
  10:  namespace ConsumeWebServiceWindows
  11:  {
  12:      public partial class Form1 : Form
  13:      {
  14:          public Form1()
  15:          {
  16:              InitializeComponent();
  17:          }
  18:   
  19:          private void button1_Click(object sender, EventArgs e)
  20:          {
  21:              HelloService.Service lobjService = new HelloService.Service();
  22:              lobjService.Credentials = System.Net.CredentialCache.DefaultCredentials;
  23:              string lstrMessage = lobjService.HelloWorld();
  24:              MessageBox.Show(lstrMessage);
  25:          }
  26:   
  27:          private void button2_Click(object sender, EventArgs e)
  28:          {
  29:              string DBLocation = txtFilePath.Text.Trim();
  30:              string TableName = "GSIS";
  31:              string FileNames = "GSIS16.xls";
  32:   
  33:              string connectionString = "Provider=Microsoft.JET.OLEDB.4.0;data source=" + DBLocation + FileNames + ";Extended Properties=\"Excel 8.0;HDR=YES;\"";
  34:              MessageBox.Show("Processing File: " + FileNames + " at: " + DateTime.Now.ToString());
  35:              OleDbConnection conn = new OleDbConnection(connectionString);
  36:   
  37:              string sql = "SELECT * FROM " + TableName;
  38:              OleDbCommand cmd = new OleDbCommand(sql, conn);
  39:              conn.Open();
  40:   
  41:              OleDbDataReader reader = cmd.ExecuteReader();
  42:              int Count = 0;
  43:              while (reader.Read())
  44:              {
  45:                  string VendorId = Convert.ToString(reader["VENDOR_ID"]).Trim();
  46:                  if (!string.IsNullOrEmpty(VendorId))
  47:                  {
  48:                      try
  49:                      {
  50:                          string lstrMessage = Convert.ToString(reader["VENDOR_NAME_LINE1"]).Trim();
  51:                          DataSet lobjSet = new DataSet();
  52:                          DataTable lobjtable = new DataTable();
  53:                          lobjSet.Tables.Add(lobjtable);
  54:                          DataColumn column = new DataColumn("Title",typeof(string));
  55:                          lobjtable.Columns.Add(column);
  56:                          DataRow row = lobjtable.Rows.Add();
  57:                          row["Title"] = lstrMessage;
  58:                          
  59:   
  60:                          HelloService.Service lobjService = new HelloService.Service();
  61:                          lobjService.Credentials = System.Net.CredentialCache.DefaultCredentials;
  62:                          string lstrMessage1 = lobjService.UpdateList(lobjSet);
  63:   
  64:                          MessageBox.Show(lstrMessage1);
  65:   
  66:   
  67:                      }
  68:                      catch (Exception ex)
  69:                      {
  70:                          MessageBox.Show(ex+ "VendorID:");
  71:                      }
  72:                  }
  73:              }
  74:   
  75:              MessageBox.Show("End Processing File: " + FileNames + " at: " + DateTime.Now.ToString());
  76:              reader.Close();
  77:              conn.Close();
  78:          }
  79:      }
  80:  }
Duplicate InternalName of the Site column
01 September 08 06:47 PM

A duplicate name "<string>" was found. at Microsoft.SharePoint.SPFieldCollection.AddFieldToWeb(String strXml, Boolean checkDisplayName) at
Microsoft.SharePoint.SPFieldCollection.AddFieldAsXmlInternal(String schemaXml, Boolean addToDefaultView, SPAddFieldOptions op) at Microsoft.SharePoint.Deployment.FieldTemplateSerializer.CreateField(SPWeb web, SerializationInfoHelper infoHelper) at Microsoft.SharePoint.Deployment.FieldTemplateSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) at
Microsoft.SharePoint.Deployment.XmlFormatter.ParseObject(Type objectType, Boolean isChildObject) at Microsoft.SharePoint.Deployment.XmlFormatter.DeserializeObject(Type objectType, Boolean isChildObject, DeploymentObject envelope) at
Microsoft.SharePoint.Deployment.XmlFormatter.Deserialize(Stream serializationStream) at Microsoft.SharePoint.Deployment.ObjectSerializer.Deserialize(Stream
serializationStream) at Microsoft.SharePoint.Deployment.ImportObjectManager.ProcessObject(XmlReader xmlReader) at Microsoft.SharePoint.Deployment.SPImport.DeserializeObjects() at Microsoft.SharePoint.Deployment.SPImport.Run()" Time="2008-07-22T22:37:58.4082752Z"
Severity="Error" Phase="ImportInProgress"

To resolve this issue, you need to deactivate & uninstall the Feature the feature and modify the Fields.xml. You need to change the one of the Site Column name. Activate & Install  the feature again.

Steps to Deactivate & Uninstall the Feature
=======================================

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>stsadm -o DeactivateFeature -name {FeatureName} -url {SiteCollection’s Url}

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>stsadm -o uninstallFeature -name {FeatureName}

Steps to Install and Activate the Feature
=====================================

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>stsadm -o installFeature -name {FeatureName}

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>stsadm -o ActivateFeature -name {FeatureName} -url {SiteCollection’s Url}

Note :- If your site is highly customized and it could be possible that you are referring these column in the object model. If anywhere the code is referring to “InternalName” Property of the these Site Column, then these changes could break your Business logic. I would strongly recommend that before doing these change, please check the source code of your customized “.dll” installed on the site .

&amp;quot;Operation is not valid due to the current state of the object&amp;quot; using the BaseFieldControl
01 September 08 06:40 PM

First, When you try to create custom links WebPart and render all the fields (Type, Edit, URL & Notes) by instantiating the BaseFieldControl  class, you will get Type & Edit field value's correctly including the images. But the Notes & URL fields gives you first record for all records.

 

   1:   // Field Value
   2:   fieldValueCell = new HtmlTableCell();
   3:   fieldControl = field.FieldRenderingControl;
   4:   fieldControl.ControlMode = SPControlMode.Display;
   5:   fieldControl.ID = Guid.NewGuid().ToString();
   6:   fieldControl.FieldName = field.InternalName;
   7:   fieldControl.ListId = this.linksList.ID;
   8:   fieldControl.ItemId = linkItem.ID;
   9:   fieldValueCell.Controls.Add(fieldControl);
 
To resolve the issue, field control have one method called GetDesigntimeHtml().

image

Once you created this WebPart and add in the page it's works fine. Wow !!!!!!!!!!!!

Add another instance of the WebPart, you will see that in second instance of the WebPart, you are getting  last records for the records' in URL and Notes field. When you debug the source in the Visual Studio, you will get the error message "Operation is not valid due to current state of an object"

You need set the "ItemContext" and "RenderContext" of the BaseFieldControl. If you create a SPContext only onetime,  assign to BaseFieldControl's "ItemContext" and "RenderContext" properties. First time when you add a webPart it a page, you will get all the control are rendering perfectly and providing you the correct data. But for the second instance of the same WebPart, the data of URL and Notes column are repeating by the last row of the list. If you debug in the Visual Studio, you will get the error message "Operation is not valid due to the current state of the object".

 

    

   1:        HtmlTable table = new HtmlTable(); 
   2:        HtmlTableRow row = null; 
   3:        HtmlTableCell fieldNameCell = null; 
   4:        HtmlTableCell fieldValueCell = null; 
   5:        SPField field = null; 
   6:        BaseFieldControl fieldControl = null; 
   7:        LiteralControl fieldValueControl = null; 
   8:        foreach (SPListItem linkItem in this.linksList.Items) 
   9:        { 
  10:             foreach (string fieldName in this.linksList.DefaultView.ViewFields) 
  11:             { 
  12:                  // Create a new row 
  13:                  row = new HtmlTableRow(); 
  14:   
  15:                  // Get the SPField instance 
  16:                  field = this.linksList.Fields.GetField(fieldName); 
  17:   
  18:                  // Field Name 
  19:                  fieldNameCell = new HtmlTableCell(); 
  20:                  fieldNameCell.InnerHtml = string.Format("{0}:&nbsp&nbsp", field.Title); 
  21:                  row.Cells.Add(fieldNameCell); 
  22:   
  23:                   // Field Value 
  24:                   fieldValueCell = new HtmlTableCell(); 
  25:                   fieldControl = field.FieldRenderingControl; 
  26:                   fieldControl.ControlMode = SPControlMode.Display; 
  27:                   fieldControl.ID = Guid.NewGuid().ToString(); 
  28:                   fieldControl.FieldName = field.InternalName; 
  29:                   fieldControl.ListId = this.linksList.ID; 
  30:                   fieldControl.ItemId = linkItem.ID; 
  31:                   fieldValueControl = new LiteralControl(fieldControl.GetDesignTimeHtml()); 
  32:                   fieldValueCell.Controls.Add(fieldValueControl); 
  33:                   row.Cells.Add(fieldValueCell); 
  34:                   // Add the row to the table 
  35:                   table.Rows.Add(row); 
  36:                 } 
  37:         } 
  38:        
For more Information, please visit  Operation is not valid due to the current state of the object
How to connect BDC with Sybase Database
15 May 08 08:39 PM

Using BDC Editor Tool we can generate metadata xml file for connecting BDC with Sybase database. For this we can either use ODBC or OLEDB connection type. To use ODBC we need to first create DSN. The DSN name along with login credentials needs to be used in the connection string. Once this is done the connection gets established with Sybase database and the tables get populated and subsequently create an instance out of it. But, when we try to execute any of the method instances it doesn't work. It fails saying "The LobSystemInstance Property 'AuthenticationMode' has a value that requires 'Trusted_Connection' in the connection string". The same error is shown even if we add Trusted_Connection in the connection string. The same application definition file when used in SharePoint also doesn't work.

 The issue is because of the XML file that is generated through the editor tool. As we are using ODBC connection, we need to manually make few changes in the XML file in order to make it work.

- First to connect BDC with Sybase Database using BDC editor tool, we need to use ODBC / OLEDB as connection type.

- The connection string should essentially look like this - Dsn=dsnname;uid=username;pwd=password;Trusted_Connection=yes;integrated security=true

- Create an instance of it and then export the file and save it locally as a XML file.

The following changes has to be done manually in the Application Definition file

1. As ODBC is used, do not put quotation marks on the SQL query. The quotation marks are generated by BDC Editor and we need to remove them.

For e.g.: Instead of Select "ProductId", "ProductName" from Products - use Select ProductId, ProductName from Products.

2. Do not put parameters like @pk. This is not accepted by ODBC Driver. It only accepts parameter using ?

For e.g.: Instead of Select "ProductName" from Products where ProductId=@pk use Select ProductName from Products where ProductId=?

3. Trusted connection should be in title case. It should be Trusted_Connection and not trusted_connection.

For e.g.: Instead of <Property Name="rdbconnection trusted_connection" Type="System.String">yes</Property> use

<Property Name="rdbconnection Trusted_Connection" Type="System.String">yes</Property>

4. If the Application definition file is to be used in BDC Data List web part then make sure that there is at least one method instance of type "Finder". By default, BDC editor tool doesn't generate method instance of finder. It generates method instance of type "IdEnumerator". So, change "IdEnumerator" to "Finder".

5. Possibilities are there when we map the Application definition file with BDC web part, it might throw an error saying "unable to connect to abc_instance". In this case change User DSN to System DSN as System DSN is globally available to all users.

 

MOSS : How to pass the FBA authenticated user to a PageViewer Web Part?
04 May 08 11:47 AM

If you creates a Form based authenticated site and you were not able to get the authenticated login user token at client site. You can use the following resolution when you are working with PageViwer Web Part.

using System;

using System.Runtime.InteropServices;

using System.Web.UI;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Serialization;

using System.Xml;

using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;

using Microsoft.SharePoint.WebPartPages;

using System.ComponentModel;

namespace FBALoginUser

{

[Guid("2ea076de-3536-4d20-b5d2-365dfd098da6")]

 

public class FBALoginUser : System.Web.UI.WebControls.WebParts.WebPart

{

public FBALoginUser()

{

this.ExportMode = WebPartExportMode.All;

}

 

protected override void Render(HtmlTextWriter writer)

{

 

SPWeb web = SPContext.GetContext(this.Context).Web ;

web.AllowUnsafeUpdates = true;

SPUser user = web.CurrentUser;

SPWebPartCollection collection = web.GetWebPartCollection ("default.aspx", Storage.Personal);

writer.Write(user.LoginName);

PageViewerWebPart lobjWebPArt = new PageViewerWebPart();

//Change to the JSP URL or youe web Application

lobjWebPArt.ContentLink = "http://localhost:4000/loginpage1.aspx?SID="+ user.LoginName.ToString() +"&VIEW=domain";

collection.Add(lobjWebPArt);

 

}

}

}

MOSS : How to get the credentails management URL
04 May 08 11:44 AM

SingleSignonLocator.GetCredentialEntryUrl Method (Microsoft.SharePoint.Portal) is reserved method. You can verify at link <http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.portal.singlesignonlocator.getcredentialentryurl.aspx> . To Get the Credentials entry URL following resolution is available.

Code Snippet

============

using Microsoft.SharePoint.Portal;

using Microsoft.SharePoint.Portal.SingleSignon;

SpsSsoProvider sso = new SpsSsoProvider();

Application.ApplicationInfo MyApp = null;

//Change the "TestingSSO" to your Application Name.

Application.GetApplication("TestingSSO", ref MyApp);

Uri returnValue = sso.GetCredentialManagementURL(MyApp.ApplicationName);

writer.Write(returnValue.OriginalString);

writer.Write("<a href=" + returnValue.OriginalString + "> Click here to save your credentials for ", "SSOServerCode</a>");

if (ControlMode == SPControlMode.Display)

{

return;

}

cblHospitals = TemplateContainer.FindControl("cblHospitals") as CheckBoxList;

if (cblHospitals == null)

{

throw new ArgumentException("cblHospitals could not be found");

}

cblHospitals.TabIndex = TabIndex;

cblHospitals.CssClass = CssClass;

SPSite site = SPContext.GetContext(this.Context).Site;

SPDataSource dataSource = new SPDataSource();

dataSource.List = site.RootWeb.Lists["Hospitals"];

this.cblHospitals.DataSource = dataSource;

this.cblHospitals.DataTextField = "Title";

this.cblHospitals.DataValueField = "Title";

this.cblHospitals.DataBind();

}

public override object Value

{

get

{

EnsureChildControls();

PublishColumnValue fieldValue = new PublishColumnValue();

foreach (ListItem item in cblHospitals.Items)

{

if (item.Selected)

{

fieldValue.Add(item.Value);

}

}

return fieldValue;

}

set

{

EnsureChildControls();

cblHospitals.ClearSelection();

PublishColumnValue fieldValue = (PublishColumnValue)value;

for (int i = 0; i < fieldValue.Count; i++)

{

string s = fieldValue[i];

if (cblHospitals.Items.FindByValue(s) != null)

{

cblHospitals.Items.FindByValue(s).Selected = true;

}

}

}

}

public override void UpdateFieldValueInItem()

{

 

base.UpdateFieldValueInItem();

}

}

 

}

 

acsx file

======

<%@ Control Language="C#" Debug="true" %>

<%@Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.WebControls"%>

Changing MasterPage programmatically for site collection and sub-sites
04 May 08 11:41 AM

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

namespace CustomMaster

{

public class ChangeMaster : Microsoft.SharePoint.SPFeatureReceiver

{

 

public override void FeatureActivated(SPFeatureReceiverProperties properties)

{

SPWeb CurrentWeb = properties.Feature.Parent as SPWeb;

CurrentWeb.MasterUrl = CurrentWeb.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/MyDefault.master";

CurrentWeb.CustomMasterUrl = CurrentWeb.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/custom.master";

CurrentWeb.Update();

foreach (SPWeb subweb in Web.GetSubwebsForCurrentUser())

{

ChangeMasterPage(subweb, pstrMasterURL, pstrCustomURL);

}

CurrentWeb.Dispose();

}

void ChangeMasterPage(SPWeb Web, string pstrMasterURL, string pstrCustomURL)

{

Web.MasterUrl = pstrMasterURL;

Web.CustomMasterUrl = pstrCustomURL;

Web.Update();

Web.Dispose();

}

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)

{

SPWeb CurrentWeb = properties.Feature.Parent as SPWeb;

CurrentWeb.MasterUrl = CurrentWeb.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/default.master";

CurrentWeb.CustomMasterUrl = CurrentWeb.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/default.master";

CurrentWeb.Update();

}

}

}

By default, In the installation of WSS3.0 setup, you didn't get the Audit logs reports option. if you enable the logs using event handler , you will not get the view logs of items.
04 May 08 11:25 AM

Create an HttpHandler using the ClassLibraryTemplate in the visual Studio 2005.

using System;

using System.Web;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

using Microsoft.SharePoint.ApplicationRuntime;

using Microsoft.SharePoint.Utilities;

using System.IO;

namespace [NameSpaceName]

{

public class [ClassName] :IHttpHandler

{

public [ClassName]()

{

}

public void ProcessRequest(HttpContext context)

{

SPFile myFile = null;

SPSite siteCollection = SPContext.Current.Site;

SPWeb web = siteCollection.OpenWeb();

web.AllowUnsafeUpdates = true;

SPList list = web.Lists["MyList"];

SPListItemCollection items = list.Items;

string URL = context.Request.Url.ToString();

Char[] param = { '/' };

String[] filename = URL.Split(param);

string path = "";

foreach (SPListItem item in items)

{

if (item.Name.ToUpper() == filename[filename.Length - 1].ToUpper().ToString())

{

item.Audit.WriteAuditEvent(SPAuditEventType.View, "CustomViewAuditEvent", "<myXml>MyData</myXml>");

item.Audit.AuditFlags = SPAuditMaskType.All;

item.Audit.Update();

myFile = item.File;

byte[] fileBuffer = myFile.OpenBinary();

path = "c:\\" + myFile.Name;

FileStream stream = new FileStream(path, FileMode.Create);

stream.Write(fileBuffer, 0, fileBuffer.Length);

stream.Close();

}

}

list.Audit.Update();

web.Update();

context.Response.WriteFile(path);

 

}

public bool IsReusable

{

// To enable pooling, return true here.

// This keeps the handler in memory.

get { return false; }

}

}

 

}

How To : Set calculated field to read-only using Object Model
02 May 08 10:49 PM

(A) Create an EventHandler using the ClassLibraryTemplate in the visual Studio 2005.

using Microsoft.SharePoint;

public class [ClassName] : SPListEventReceiver

{

public override void FieldUpdating(SPListEventProperties properties)

{

properties.ErrorMessage = "You can't changed the column.";

properties.Cancel = true;

}

}

(B) Register the Event Handler using the following Code.

// http://tangov39:47242/sites/TestCase/ is the site URL.

SPSite collection = new SPSite("http://tangov39:47242/sites/TestCase/");

SPWeb site = collection.OpenWeb();

// Here test2 is document List Name.

SPList test2 = site.Lists["test2"];

 

string asmName = "DaveHandlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b5e8677dbb56bf06";

string className = "DaveHandlers.ReadOnlyHandlers";

test2.EventReceivers.Add(SPEventReceiverType.FieldUpdating, asmName, className);

 

STEPS TO REPRO:

====================

1. Create a list or document library

2. Add/create a new column, select Calculated (calculation based on other columns) field with formula eg = 3*4, be sure to select number as the return data type.

3. Add a few new entries to the list or library.

4. Select edit in datasheet.

5. Attempt to edit the value of the calculated field with some numberic value.

6. You may be prompted for a username/password if the signed in user does not have security permissions. If so sign in with a username/password of an account with a username / password with adequate permissions

7. When the preview/warning message box appears, click continue.

8. Notice the calculated value was changed for each row and if you go back into list settings. You'll see the forumla has changed.

More Posts « Previous page

This Blog

Syndication

Page view tracker