Showing posts with label Sharepoint 2007. Show all posts
Showing posts with label Sharepoint 2007. Show all posts

Thursday, August 19, 2010

How to display the ID number on edit and display forms in SharePoint 2007?

  1. We will use the content editor webpart to add Javascript that will display the ID. However, most edit and display forms do not allow you to add a webpart. This can be easily rectified by adding "&ToolPaneView=2" to the URL in the browser address line.
  2. Add a content editor webpart right above the form. Set the "Chome Type" to none in the "Appearance" section of the webpart.
  3. Click on the "Source Editor" button of the webpart.
  4. Add the following HTML/Javascript:
<script type="text/javascript">

//
// Item ID in DispForm.aspx and EditForm.aspx
//
function DisplayItemID()
{
   var regex = new RegExp("[\\?&]"+"ID"+"=([^&#]*)");
   var qs = regex.exec(window.location.href);
   var TD1 = document.createElement("TD");
   TD1.className = "ms-formlabel";
   TD1.innerHTML = "<h3 class='ms-standardheader'>ID</h3>";
   var TD2 = document.createElement("TD");
   TD2.className = "ms-formbody";
   TD2.innerHTML = qs[1];
   var IdRow = document.createElement("TR");
   IdRow.appendChild(TD1);
   IdRow.appendChild(TD2);
   var ItemBody = GetSelectedElement(document.getElementById("idAttachmentsRow"),"TABLE").getElementsByTagName("TBODY")[0];
   ItemBody.insertBefore(IdRow,ItemBody.firstChild);
}
_spBodyOnLoadFunctionNames.push("DisplayItemID");
</script>

Wednesday, December 2, 2009

How do you add a list ID to a form?

Add a calculated field column with formula "=ID".

Wednesday, September 23, 2009

Tweaking IIS & web.config connection timeout setting

Microsoft Internet Information Services
If IIS is timing out when you upload large files, you can change "Connection Timeout" property to ensure that larger files can be uploaded successfully.
  1. Go to Start –> All Programs -> Administrative Tools –> Internet Information Services (IIS) Manager.
  2. Right-click the virtual server you want to configure, and then choose Properties.
  3. Click the Web Site tab.
  4. In the Connections section, in the Connection timeout box, type the number of seconds you want IIS to wait before timing out.
  5. Click OK to save settings.
Web.config

There are other settings that you can change in the web.config file that also affect connection timeout.

Update maxRequestLength and executionTimeout attributes belonging to the httpRuntime tag.

executionTimeout = <Time in Seconds>

maxRequestLength = <File size in KB> (by default for ASP.NET applications, its set to 4096 (4MB), but because SharePoint supports 50MB so its set to 51200)

Example:

<!-- 102400 = 100MB -->
<httpRuntime executionTimeout="999999" maxRequestLength="102400" />


Extending session timeout for SharePoint 2007 instance using forms-based autentication.

Change the timeout attribute belonging to the forms tag in the web.config file:

<forms loginUrl="Login.aspx" timeout="300"/>

This will force a timeout in 5 minutes of inactivity.

This setting equally applies to any ASP.NET application that uses forms-based authentication.

Wednesday, June 24, 2009

How to unsubscribe (or remove) yourself from a SharePoint 2007 alert?

In SharePoint one can subscribe to any document libraray or list to be sent alerts when changes occur such us additions, deletions, and updates. This is done by choosing "Actions" => "Alert Me".


If one wishes not to receive alerts anymore, it is not that apparent how to do it. Well, you would need to go to "Site Actions" => "Site Settings" => "User Alerts". Choose the user in question and subsequently delete him/her from the appropriate list or document library alert.

Friday, March 6, 2009

Enabling Entity Framework (ADO.NET Entity Data Model) in a SharePoint 2007 web.config file

The Entity Framework is considered to be the modern day successor to "LINQ to SQL". If you wish to use this technology in a SharePoint 2007 web part you will need to tweak your web.config file to accomodate the new assemblies that are associated with the Entity Framework. Here are the changes that you need to apply to your web.config file:


1) Add the following tags to the <compilation><assemblies> section:

<add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />

<add assembly="System.Data.Entity.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />

<add assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />

2) Add the following tags to the <compilation> section just under the closing </assemblies> tag:

<buildProviders>

<add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" />

</buildProviders>

Tuesday, March 3, 2009

How can you get the thumbnail for an image in your SharePoint picture library?

This is much easier than I had imagined. At first I thought I need to do some programming with the SharePoint Object Model APIs. It turned out to be nothing of the sort.


Let us assume that you have a photograph located in your picture library named "pictures" at this URL:

http://www.spserver.com/spsite/pictures/joe_smith.jpg

The thumbnail for the above picture is located at:

http://www.spserver.com/spsite/pictures/_t/joe_smith_jpg.jpg

As you can see, here's what I did:

1) tag a directory "_t" to the the URL just before the filename.

2) tag "_jpg" to the filename just before the extention. This would have been "_gif" if you are dealing with a GIF file.

Voila, if you point your browser to this tweaked URL you will get your thumbnail.

You will get a larger image if you use _w instead of _t.

Painless eh. . .

Wednesday, November 26, 2008

Download tracking with WSS 3.0

WSS 3.0 does not have a mechanism for tracking who downloads which files with authenticated users. When I got confronted with this task, I decided to create a web user control that reads all the files in a document library and subsequently displays the file names using a series of "LinkButton" controls. I then attached this web user control to a SharePoint WSS 3.0 web page. I decided against using a Hyperlink object in favor of a LinkButton ASP.NET control for the following two reasons:


1) With a HyperLink ASP.NET control, users can right-click on the anchor and choose "Save target as" to save the file. This is not desirable because no event is triggered when that happens. On the other hand, a LinkButton control does not produce a right-click popup in a browser leaving the user with no choice but to click on the link.

2) I needed to put some business logic behind the click event of the LinkButton. The business logic essentially saves statistics along the lines of: timestamp, host address, user ID, and filename.

Wednesday, October 22, 2008

How to programatically delete a SharePoint 2007 field belonging to a list or document library?

Here's the code for deleting a field named "phone" in list "myList" on a site with URL http://mysite/:


try {

using (SPSite sitecollection = new SPSite("http://mysite/")) {

using (SPWeb web = sitecollection.OpenWeb()) {

web.AllowUnsafeUpdates = true;

// Delete Sharepoint SPField

web.Lists["myList"].Fields.Delete("phone");

web.Update();

Console.WriteLine("Done deleting column");

}

}

} catch (Exception ex) {

Console.WriteLine(ex.ToString());

}

Tuesday, October 21, 2008

How do you break up a long SharePoint 2007 survey?

What do you do if you have a long SharePoint 2007 survey and you want to break it up into separate pages such that the user needs to click the "Next" button?


Solution:

You must use branching on selected questions for this. All branching items would simply point to the next question. That produces a “Next” button.

Thursday, July 24, 2008

How to use built-in SharePoint 2007 engine to send email?

A straightforward way of sending email from within a SharePoint 2007 application is to use the Object Model. Here is some C# code that will do it for you:


bool isAppendHtmlTag = true;
bool isHtmlEncode = false;
string recipient = "whoever@whatever.com";
string title = "This is the title";
string body = "This is the email <strong>body</strong>";

Microsoft.SharePoint.Utilities.SPUtility.SendEmail(
Microsoft.SharePoint.SPContext.Current.Web,
isAppendHtmlTag,
isHtmlEncode,
recipient,title,
body);

Sunday, July 20, 2008

Generating user instances in SQL Server is disabled. Use sp_configure 'user instances enabled' to generate user instances.

Recently I noticed that many of my ASP.NET applications that work with a SQL Server Express database that resides in the App_Data directory stopped working. The culprit error was "Generating user instances in SQL Server is disabled. Use sp_configure 'user instances enabled' to generate user instances.". I suspect that a SQL Server update went out that disables user instances. I have not been able to substantiate this suspicion yet.


SOLUTION:

The solution is to enable user instances with the following command:

sp_configure 'user instances enabled','1';

Disable user instances with the following command:

sp_configure 'user instances enabled','0';

Friday, July 18, 2008

How to edit group on the SharePoint quicklaunch in WSS 3.0 (and MOSS 2007)?

It is always a good idea to lock down SharePoint sites such that users do not see more information than they need to. At the organization where I work, we have a plethora of SharePoint groups. With any new website that gets created, a user with full rights gets to see a list of all the groups by going to "Site Actions / Site Settings / Advanced Permissions". There is always the danger that a user can inadvertently delete or add a user to the wrong group. One simple solution is to remove unneeded groups from the quicklaunch. Here's what you can do:
  • Click on Site Actions / Site Settings / Advanced Permissions
  • Click on any group on the quicklaunch under "Groups"
  • Click on Settings / Edit Group Quick Launch
  • On the "Edit Group Quick Launch" page, highlight any group and hit the delete key on your keyboard

 

Wednesday, July 2, 2008

What is an easy way to find out the internal name of a SharePoint 2007 list column?

The internal name of a SharePoint list column can be different from the display name. This could happen if a column name has been renamed to something else. For example, if you rename the "Title" column to, say, "Company Name", the internal name remains as "Title". Also, spaces in the display name are replaced with "_x0020_" in the internal name. The internal name of "Contract_x0020_Type" would be used for display name "Contract Type".


An easy way to discover the internal name without any programming is:

- add the column to a view
- click on the column name to sort the view by that column
- check the URL for the "SortField=" parameter value.

I did this for a column name "Company Name" and got a URL similar to this:

http://www.domain.com/records/Documents/Forms/AllItems.aspx?SortField=Company%5fx0020%5fName&SortDir=Asc&View=%7b0E0FDBDA%2d1BA5%2d4CE1%2dBEE4%2d191B285E1F8A%7d

The above URL suggests that the internal field for "Compnay Name" is "Company_x0020_Name".

Note that the URL encoding for the underscore is "%5f".

Tuesday, May 20, 2008

How to upgrade SharePoint 2007 web.config file from .NET Framework 3.0 to .NET Framework 3.5 support?

In order to take advantage of some of the great features of .NET Framework 3.5 in your SharePoint 2007, you will need to upgrade the web.config file. Some new features are LINQ, AJAX, and new controls like ListView. Here's a step-by-step task list of what needs to be added. Before we go on, make sure that you have installed the .NET Framework version 3.5 on the server. Also, make a backup copy of your SharePoint 2007 web.config file.
1) Add the following inside of the <configSections> tag block:

<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>

<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

</sectionGroup>

</sectionGroup>

</sectionGroup>

2) Add the following inside of the <httpHandlers> tag block:

<remove verb="*" path="*.asmx" />

<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

<add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

3) Add the following inside of the <httpModules> tag block:

<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

4) Add the following inside of the <assemblies> tag block:

<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

5) Add the following inside of the <pages> tag block:

<controls>

<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

</controls>

6) Add the following right before </configuration>:

<system.codedom>

<compilers>

<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">

<providerOption name="CompilerVersion" value="v3.5" />

<providerOption name="WarnAsError" value="false" />

</compiler>

<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">

<providerOption name="CompilerVersion" value="v3.5" />

<providerOption name="OptionInfer" value="true" />

<providerOption name="WarnAsError" value="false" />

</compiler>

</compilers>

</system.codedom>

<system.webServer>

<validation validateIntegratedModeConfiguration="false" />

<modules>

<remove name="ScriptModule" />

<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

</modules>

<handlers>

<remove name="WebServiceHandlerFactory-Integrated" />

<remove name="ScriptHandlerFactory" />

<remove name="ScriptHandlerFactoryAppServices" />

<remove name="ScriptResource" />

<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

<add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

</handlers>

</system.webServer>

Wednesday, April 30, 2008

How to get the whole announcement to show up in SharePoint 2007?

  1. Go into the Announcements section by clicking on the title.
  2. Create a new view based on the existing default. I called mine "All items with Body"
  3. Make sure the 'body' column is checked, and select "Newsletter" under Style.
  4. Go back to your main page, and select 'edit shared web part' for the announcements section you're working on.
  5. Change the view to be the new view you just created and click OK.

Tuesday, April 29, 2008

How to exclude content in a SharePoint 2007 site from being indexed by the search engine?

There are circumstances whereby content in a specific site needs to be excluded from the SharePoint 2007 search engine indexing process. This can be done at a list level and/or a site level.


 

 List level:
  • Settings / List Settings
  • Click on "Advanced Settings"
  • At the very botton under "Search" set "Allow items from this list to appear in search results?" to "No"
  • Click "OK" button
Site level:
  • Site Actions / Site Settings
  • under "Site Administration" click on "Search visibility"
  • set "Allow this web to appear in search results?" to "No"
  • Also choose "Never index any ASPX pages on this site" radio button
  • Click "OK" button
Remember to reindex search results in central administration so that these new rules immediately take effect. One way to do this is as follows:
  • On the SharePoint server, get into the "Central Administration" web application
  • Click on the "Shared Services Administration" link on the left-hand-side
  • Select "Open Shared Services Admin Site" from the dropdownlist of the default SSP site
  • Click on "Search settings" link under "Search"
  • Click on the link beside "Content sources:"
  • Select "Start Full Crawl" from the dropdownlist of the content source

Friday, February 29, 2008

How to hide View: menu on the right-hand-side of the SharePoint 2007 toolbar?

  • Display the view in a browser
  • Open the source in an editor. This is done by "right-click / view source" in IE
  • Search for "ms-listheaderlabel". It will land on a <td> tag.
  • Right under that <td> tag you will find another <td> tag with an ID like: ctl00_m_g_672c28cb_9a7b_4898_a26c_22eefe71074d_ctl00_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_onetViewSelector
  • Copy the ID into the clipboard.
  • Create a style in an editor as follows and use the ID that you copied into the clipboard:

<style type="text/css">

 
#ctl00_m_g_672c28cb_9a7b_4898_a26c_22eefe71074d_ctl00_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_onetViewSelector{

visibility:hidden;

}

.ms-listheaderlabel {

visibility:hidden;

}

 

</style>
  • Click on "Site Actions / Edit Page"
  • Add "Content Editor Web Part" to the page.
  • Cick on "open the tool pane"
  • Click on the "Source Editor ..." button on the far right-hand-side of the page
  • Copy and paste the <script ...> code from your editor into the "Text Entry -- Webpage Dialog"
  • Click "Save" button
  • Click "OK" button
  • Click "Exit Edit Mode" link.

Wednesday, February 13, 2008

How to enable session state in SharePoint WSS 3.0?

Before you can use sessions you first have to enable the session state module in the web.config file in a WSS 3.0 sharepoint site. Just uncomment the following line:


<!—
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
-->

After that you can use the session object like you'll normally do with any ASP.NET web applications.

Thursday, January 3, 2008

Unable to delete or customize a choice field in WSS 3.0

I needed to customize the HelpDesk template that is freely downloadable from Microsoft. I discovered that it is not possible to add any choice items or even delete the column. Here's what I experienced when I clicked on:
Service Requests ==> Site Settings ==> List Settings ==> Status

You will notice that the "Delete" button is missing and no choice items can be changed.
I discovered that the choice field is sealed in the feature template itself.

Solution:

1) Open the schema.xml file located in the SharePoint 2007 12-hives directory at:

%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\HelpDeskServiceRequestsList\servicerequest

2) Search for the Status field.

<Field ID="{75AF1E7D-39F1-45db-908A-B7AD3F26531A}"

Type="Choice"

Name="Status"

DisplayName="$Resources:hlpdsk,SRStatus;"

StaticName="Status"

Required="TRUE"

Sealed="TRUE"

Format="Dropdown"

FillInChoice="FALSE"

SourceID="http://schemas.microsoft.com/sharepoint/v3"

>

<Default>$Resources:hlpdsk,SRStatus_Choice1;</Default>

<CHOICES>

<CHOICE>$Resources:hlpdsk,SRStatus_Choice1;</CHOICE>

<CHOICE>$Resources:hlpdsk,SRStatus_Choice2;</CHOICE>

<CHOICE>$Resources:hlpdsk,SRStatus_Choice3;</CHOICE>

<CHOICE>$Resources:hlpdsk,SRStatus_Choice4;</CHOICE>

</CHOICES>

</Field>

3) Change the Sealed attribute value from TRUE to FALSE

4) Save the schema.xml file

5) Restart IIS