Wednesday, December 30, 2009

View a detailed error in sharepoint

To View a detailed error in sharepoint, you need to follow below steps in your site’s web.config file .


Step 1: Change 'CallStack' value from false to true in SafeMode attribute as shown below.
[SafeMode MaxControls="200" CallStack="false" .../]
To
[SafeMode MaxControls="200" CallStack="true" .../]


Step2: Change 'customErrors' tag mode from ‘On’ to ‘Off’.
[customErrors mode="On" /]
To
[customErrors mode="Off" /]


Step3: Change 'Debug' from 'false' to 'true' in 'Compilation' attribute.
[compilation batch="false" debug="false"]
To
[compilation batch="false" debug="true"]


Step 4: Restart the IIS.

Tuesday, September 29, 2009

An error has occurred after workflow completed MOSS 2007

If you have a "built in" or custom approval workflow setup for your document library. The workflow runs correctly, however sometimes you look at the workflow status, you may receive an error after the task has been approved and completed such as,
Event Type: Error User ID: System Account Description: An error has occurred in [your workflow name].
Resolution: There is a section "Post-completion Workflow Activities", where you can check "Update the approval status (use this workflow to control content approval)". If you check this option, and you do NOT have content approval enabled on the library level, you get the system account error message. If you do not check it, everything works fine.

Thursday, September 3, 2009

Most common problems in SharePoint naming: spaces

When I did create a workflow action, Using SharePoint Designer 2007, which emails the URL of the current item in a list. I did use below lookup items in my workflow mail
1-[%LISTNAME: Encoded Absolute URL %]
2-[%LISTNAME: Server Relative URL%]
3-[%LISTNAME: URL Path %]
4-[%LISTNAME: Path %]

There is one problem which will always occur and another which may occur, depending upon the naming convention you use for your lists.

Problem 1: ID number pulled from URL actions are appended with "_.000" in case 1, 2 and 3.
Problem 2: In case 4, Spaces within list names are sometimes ignored, sometimes not. i.e. "My Test List" could be translated into "My Test %20List" - causing a 404 error during the URL lookup.

Solution: Here I am solving problem 2. It works for me. According this,

You need to rename your lists to contain no spaces. Now this would seem easy to do - enter your list settings, go to Title, description and navigation, and change the name. This will not work as it seems to only change a pointer for SharePoint references, but not anything that has to do with URL paths.

You need to rename the list itself within SharePoint Designer to have one single list name. Right-click on the selected list, select "rename" and rename the list to something without spaces. SharePoint Designer will save this information to your SharePoint site and references in all attached workflows will reflect these changes.

Basically this changes internal name of list. Now you can rename list name again from SharePoint list setting, go to Title, description and navigation, and change the name, if you need to display list title with space to all.

Wednesday, September 2, 2009

Error "401 Unauthorized" For MOSS FBA

When you have SharePoint Server 2007 implementation with Form Based Authentication (FBA) and anonymous access turned on you may experience 401 Unauthorized when you visit the site like http://xxxxxx/sites123/pages123/default.aspx

Look into your web.config file for Web Application that you extended to use FBA for *compilation* tag and edit it to make it look like below. Save the web.config and give it a run.

*compilation batch="false" debug="false" /*

Note: Please replace * (Blogger not support HTML tagging)

And also when you visit the URL could you please check which Zone does the site belong to in the IE status bar?
I suppose the URL belongs to the Local Intranet Zone or Trusted Sites which automatically log on with your current Windows credential. If your windows credential does not have the permission to access the site, you would get 401 Unauthorized error. If so, please remove the sites from the Local Intranet Zone or Trusted Sites and try again.

Hope it will help !! :-)

Tuesday, August 25, 2009

Change SharePoint 'Document library/List' Column width

Sometimes we need to change default column width of document library/list.To change sharepoint document library/list column we need to add a content editor webpart on that perticular page and need to write below code as javascript script. (use below code within javascript tag)

_spBodyOnLoadFunctionNames.push("ModifiyCommentWidth");
function ModifiyCommentWidth() {
for (var i = 0, l = document.getElementsByTagName("TH").length; i < l; i++) { var thisTH = document.getElementsByTagName("TH")[i]; if (thisTH.className == 'ms-vh2-nograd') { if (thisTH.innerText == 'Comments') {
thisTH.style.width = "300px";
}
}


Please ensure tag name before use this line of code because this is not same for all. This is working in my case but you need to update tag names accordingly.

Tuesday, August 18, 2009

ListTemplateId for Event List

  1. GenericList 100
  2. DocumentLibrary 101
  3. Survey 102
  4. Links 103
  5. Announcements 104
  6. Contacts 105
  7. Events 106
  8. Tasks 107
  9. DiscussionBoard 108
  10. PictureLibrary 109

Events = Calendar = 106

Workflow Status Fields Named/Value Pairs


Not Started 0
Failed on Start 1
In Progress 2
Error Occurred 3
Canceled 4
Completed 5
Failed on Start (retrying) 6
Error Occurred (retrying) 7
Canceled 15
Approved 16
Rejected 17

Wednesday, June 10, 2009

Programmatically Upload a file from Local path to sharepoint document library [c#]

Here code is using FileUpload control to get a file from local system path.After getting this local file path ,below is code which helps to add this file to sharepoint document library.

/*Function ‘isFileExist’ use to get local file path as 'sourceFilePath' and document library path as 'targetDocumentLibraryPath' it calls function 'UploadFile' to upload sourceFile in targetDocumentLibrary.*/

public void isFileExist()
{
if(_fileUpload.HasFile)
{
string sourceFilePath = _fileUpload.PostedFile.FileName.ToString();
sourceFilePath = sourceFilePath.Replace("%20", " ");
sourceFilePath = sourceFilePath.Replace('\\', '/');
string targetDocumentLibraryPath = string.Empty;
using (SPSite osite = new SPSite(SiteURL))
{
targetDocumentLibraryPath = osite.Url + DocLibName + "/";
}
targetDocumentLibraryPath = targetDocumentLibraryPath.Replace("%20", " ");
targetDocumentLibraryPath = targetDocumentLibraryPath.Replace('\\', '/');
SPFile _File = UploadFile( _fileUpload.FileName, sourceFilePath, targetDocumentLibraryPath);
}
}

/*Function ‘UploadFile’ takes file from local system as a stream and add this stream to sharepoint document library.*/

public SPFile UploadFile(string fileName, string srcUrl, string destUrl)
{
if (!File.Exists(srcUrl))
{
throw new ArgumentException(String.Format("{0} does not exist", srcUrl), "srcUrl");
}
SPWeb site = new SPSite(destUrl).OpenWeb();
FileStream fStream = File.OpenRead(srcUrl);
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
SPFile uploadedFile = site.Folders[destUrl].Files.Add(destUrl + fileName, contents);
return uploadedFile;
}

Tuesday, May 26, 2009

Difference between methods SPListItem.Update() and SPListItem.SystemUpdate()

There are two methods provided by SharePoint object model to update a list item.
i) Update()
ii) SystemUpdate().
Both are working fine to update a list but there is some difference between both methods. Let’s see

SPListItem.Update () : Updates the database with changes made to the list item.

SPList list = web.Lists["myList"];
SPListItem item = list.Items[0];
item["myField"] = "my value";
item.Update();


This works fine and update particular list item. Basically this is creating new version of that list item. It update ‘Modified’ and ‘Modified by’ value as well.
But in some cases where no need to create new version of list item like during migration or some where there is no need to update modified date and modified by. For that situation function ‘SystemUpdate()’ works fine.

SPListItem.SystemUpdate () : Updates the database with changes made to the list item, without effecting changes in the Modified or Modified By fields.

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

SPListItem item = list.Items[0];
item["myField"] = "my value";
item.SystemUpdate();

SystemUpdate method ignore changing modified date and modifier fields.
item.SystemUpdate(false);
If Argument 'false' use with this method than it tells that no new versions are expected.

Monday, May 18, 2009

Sending mail in SharePoint [c# ]

We can send mail to any where with the help of c# custom code. Below given code use setting from ‘Outgoing e-mail setting’. This is out of box functionality of SharePoint. Therefore before using this code, configure this from Central Administration.

Libraries which you have to add above the code.
using System.Net.Mail;
using Microsoft.SharePoint;

Below code shows functionality to send mail.

public void SendMail()
{
try
{
Microsoft.SharePoint.Administration.SPGlobalAdmin globAdmin = new Microsoft.SharePoint.Administration.SPGlobalAdmin();
MailMessage objEmail = new MailMessage(FromMail, ToMail,Subject,Body);
objEmail.IsBodyHtml = true;
objEmail.Priority = MailPriority.Normal;
SmtpClient smtp = new SmtpClient(globAdmin.OutboundSmtpServer);
smtp.Send(objEmail);
}
catch
{
throw;
}
}

Friday, April 10, 2009

Using browser enable Infopath form as a class [C#]

I was facing a problem when I had needed a dot net utility to get data from browser enable InfoPath form and save this to another custom list. These steps and code will help to use an browser enable InfoPath form as a Dot Net class.
For using browser enable InfoPath as a class first you need to follow these steps,
 Create a browser enable InfoPath Form.
 Save it’s source file by selecting ‘Save As Source Files…’.




After click ‘Save As Source Files…’, you need to provide path to save this form schema on your location. You can check that ‘MySchema.xsd’ will also one of all files saved on your provided path.
Now Go to Start Menu -> All Programs ->Microsoft Visual Studio 2005 -> Visual Studio Tools ->Visual Studio 2005 Command Prompt



It will display Visual Studio Command prompt. Now navigate to your folder where you have save you InfoPath form schema (MySchema.xsd).

Now you need to run command

Xsd.exe /c /l:CS myschema.xsd

Remember that source infopath form will be closed before executing this command.It will create “myschema.cs” in same folder. This class will look like this…

---------------------------------------------------------------------------------
using System.Xml.Serialization;

//
// This source code was auto-generated by xsd, Version=2.0.50727.42.
//


///
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-04-09T04:39:44")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-04-09T04:39:44", IsNullable=false)]
public partial class myFields {

---------------------------------------------------------------------------------

you can use all properties of class ‘myFields’.

Now as per requirement, Suppose there is a document library (Suppose _doclib) where all infopath forms has saved.Let take a item (Suppose ID = 1) of that library.


C# Code:


SPListItem item = _doclib.Items.GetItemById(1);
SPFile InfoPathFile = item.File;
if (InfoPathFile != null)
{
Stream inStream = InfoPathFile.OpenBinaryStream(SPOpenBinaryOptions.None);
XmlTextReader reader = new XmlTextReader(inStream);
myFields objForm = (myFields)DeserializeFile(InfoPathFile, typeof(myFields));
}
protected static object DeserializeFile(SPFile myFile, Type myType)
{
MemoryStream fileStream = new MemoryStream(myFile.OpenBinary());
XmlReader reader = XmlReader.Create(fileStream);
XmlSerializer serializer = new XmlSerializer(myType);
return serializer.Deserialize(reader);
}

Now ‘objForm’ will have all values of that perticular infopath form.just use this objForm and enjoy…