Pages

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

Monday, November 22, 2010

Windows SharePoint Services Timer Status is Stopping

Hello Readers,

I have started to take the backup of SharePoint Farm on one SharePoint server through SharePoint Central Administration.

But it was not giving me any status for starting, Central Admin has given one tips that if it does not automatically start, check Timer Job Definitions or Timer Job Status.

I went to Timer Job Status from SharePoint Central Administration -> Operations->Timer Job Status (Timer Job Status, you will find under “Global Configuration” Sections of “Operations”.

I checked “Application Server Administration Service Timer Job” was initialized but did not success .Then I went to Start->Administrative Tools->Services and I have restarted and it gives me this error .

"Windows SharePoint Services Timer Status is Stopping"


How to solve the problem:
Let us look at the step by step process.
1> End OWSTimer.exe Process from the task manager
      a.       Go to Task Manager and in Process Tab find the OWSTimer.exe, select that process and click button “End Process”.
2>  Click on Windows SharePoint Service Timer, Go to recovery tab, Change Setting of First Failure and Second Failure.
3>  First Failure Change options to Take No Action
4>  Second Failure Change options to Take No Action


5>     Press Ok and Press F5 Refresh Service Page.
6>     Now you can find the “start” option, start it and it is running now.
You have solved the Problem!!!
Enjoy!!
Disha Shah


Wednesday, September 15, 2010

Sharepoint 2007 - LIST OF MAPPING OF VIRTUAL FOLDERS WITH PHYSICAL FOLDERSPATH

Hey All

Here you can find a list of Mapping of Virtual Folders With Physical Folder Path in Sharepoint 2007.

LocalDrive:\>iisvdir/query “Sharepoint-80”

No.


Alias


Physical Root

1>/_controltemplatesLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES
2>/_layoutsLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS
3>/_vti_binLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI
4>/_wpresourcesLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\wpresources

LocalDrive:\>iisvdir/query “sharepoint Central Administration v3”

No.AliasPhysical Root
1>/_adminLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\ADMIN
2>/_controltemplatesLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES
3>/_layoutsLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS
4>/_vti_admLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ADMISAPI
5>/_vti_binLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI
6>/_wpresourcesLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\wpresources

LocalDrive:\>iisvdir/query “Office Server web services”

No.AliasPhysical Root
1>/SharedServices1LocalDrive:\Program Files\Microsoft Office Servers\12.0\WebServices\Shared

LocalDrive:\>iisvdir/query “Sharepoint - 46281”

No.AliasPhysical Root
1>/_controltemplatesLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES
2>/_layoutsLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS
3>/_vti_binLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI
4>/_wpresourcesLocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\wpresources

So Find out files!!!
Disha Shah

How to apply custom master page into SharePoint Site

You can get information regarding master page and branding from below article.

http://dishasharepointworld.blogspot.com/2009/08/sharepoint-master-pages-and-branding_13.html

In this article, I’ll share with you how to apply custom master page into SharePoint root site and its sub sites, here I have created one feature in which I applied custom master page code into Feature Activated Event.

Example Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Collections;
namespace ApplymasterPage
{
class ApplyMasterPage : Microsoft.SharePoint.SPFeatureReceiver
{
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
if (site == null)
return;
SPWeb rootWeb = site.RootWeb;
DeactivateWeb(rootWeb);
rootWeb.Update();
foreach (SPWeb subWeb in rootWeb.Webs)
{
ProcessSubWebs(subWeb,
false);
}
}
private void DeactivateWeb(SPWeb web)
{
if (web.AllProperties.ContainsKey("OldMasterUrl"))
{
string oldMasterUrl = web.AllProperties["OldMasterUrl"].ToString();
try
{
bool fileExists = web.GetFile(oldMasterUrl).Exists;
web.MasterUrl = oldMasterUrl;
}
catch (ArgumentException)
{
web.MasterUrl = defaultMasterUrl;
}
string oldCustomUrl = web.AllProperties["OldCustomMasterUrl"].ToString();
try
{
bool fileExists = web.GetFile(oldCustomUrl).Exists;
web.CustomMasterUrl = web.AllProperties[
"OldCustomMasterUrl"].ToString();
}
catch (ArgumentException)
{
web.CustomMasterUrl = defaultMasterUrl;
}
web.AllProperties.Remove("OldMasterUrl");
web.AllProperties.Remove("OldCustomMasterUrl");
}
else
{
web.MasterUrl = defaultMasterUrl;
web.CustomMasterUrl = defaultMasterUrl;
}
}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
}
const string defaultMasterUrl = "/_catalogs/masterpage/default.master";
const string customizedMasterUrl = "/_catalogs/masterpage/Custom.master";

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
if (site == null)
return;
SPWeb rootWeb = site.RootWeb;
rootWeb.AllProperties["OldMasterUrl"] = rootWeb.MasterUrl;
rootWeb.AllProperties["OldCustomMasterUrl"] = rootWeb.CustomMasterUrl;
rootWeb.MasterUrl = customizedMasterUrl;
rootWeb.CustomMasterUrl = customizedMasterUrl;
rootWeb.Update();
foreach (SPWeb subWeb in rootWeb.Webs)
{
ProcessSubWebs(subWeb,true);
}
}
private void ProcessSubWebs(SPWeb web, bool isActivation)
{
if (isActivation)
{
web.AllProperties["OldMasterUrl"] = web.MasterUrl;
web.AllProperties["OldCustomMasterUrl"] = web.CustomMasterUrl;
web.MasterUrl = web.Site.RootWeb.MasterUrl;
web.CustomMasterUrl = web.Site.RootWeb.MasterUrl;
}
else
{
DeactivateWeb(web);
}
web.Update();
foreach (SPWeb subWeb in web.Webs)
{
ProcessSubWebs(subWeb, isActivation);
}
}

}
}

Monday, November 16, 2009

Site Navigation in SharePoint


Navigation
is very important in any application. Navigation provides the way for the user to travel with in application.

Today I'll talk about Site Navigations in SharePoint.

  1. Global navigation (typically the top navigation)

  2. The current navigation (typically the left - hand navigation)


We can change the navigation by below two ways.

  1. Browser - Based Customizations


Publishing sites have a navigation customization capability through the browser. Navigating to the site’s Site Settings page and selecting Navigation under option. The Look and Feel section brings the user to the Site Navigation Settings page. From this page the site can be configured to include or exclude either sub sites and/or pages from the main navigation. In addition to the scoping options, owners can also select to manually or automatically sort navigation.

2. Changing Navigation Programmatically with the API
Below are custom Properties available with API.

1>  IncludeSubSites and IncludePages properties accept one of three values:
1.1> Always, 1.2> PerWeb, and 1.3>Never.

2> IncludeHeadings and IncludeAuthoredLinks properties are Boolean values that enable the site administrator to allow or block the inclusion of custom links and headings in the navigation.

We can add a new navigation code by using “Microsoft.SharePoint.Navigation.SPNavigationNode” class and then we need to add them in proper navigation collection.

Snippets code

SPWeb site = SPContext.Current.Web;


// get a reference to the top navigation


SPNavigationNodeCollection topNavigation = site.Navigation.TopNavigationBar;


// or get a reference to the Quick Launch navigation


// SPNavigationNodeCollection quickLaunchNav = site.Navigation.QuickLaunch;


// create new drop down menu in the navigation


SPNavigationNode newMenu = new SPNavigationNode(“External Links”, “”, false);


// add the new menu to the end of the top nav bar


topNavigation.AddAsLast(newMenu);


// add a custom link


newMenu.Children.AddAsLast(new SPNavigationNode(“Google”,“http://www.google.com”,true));



Let’s try something new into SharePoint other then out of the box functionality!

Friday, November 13, 2009

Double Hop Problem in SharePoint

Hello Friends,

I have faced problem when I built a web part which takes a main file and from that file I need to access all files of respective directory by directory.getfiles method and every time I got error “Could not find a part of this path (path)” .

I tried so many other solutions like I used windows Identity but didn’t get success. It seems that if SharePoint web application hosts on another server and if we try to access file from another local system then it’s not working.


At the last I have found out that it’s related to Double Hop Problem.

According to Microsoft KB article:


The double-hop issue is when the ASPX page tries to use resources that are located on a server that is different from the IIS server.


I read about Double Hob problem into SharePoint, and solved by using Kerberos authentication.

I have followed this link to solved my problem:


http://technet.microsoft.com/en-us/library/cc263449.aspx


Enjoy Debugging!
Disha Shah

Thursday, August 13, 2009

SharePoint Master Pages and Branding

Today I’ll talk about master pages and branding fundamentals into SharePoint :)

Every WSS 3.0 site is provisioned with a special Master Page gallery which contains a master page template known as default.master. This file is deployed in the 12-hive under 12\TEMPLATE\GLOBAL. Each new WSS site provides an instance of default.master. It is possible to customize default.master, but if you do, it becomes unghosted and this can affect efficiently and scalability.

The default.master page contains controls (including links, menus, icons and navigation components), named placeholders, and delegate controls. Named placeholders are used to add unique contents to a page template of page instance that is linked to a master page. Delegate Controls provide a way to substitute elements into the master page layout that affect every site. Delegate Controls are changed via activating features; therefore modifications to delegate controls require no changes to the default.master or site pages that are linked to default.master.

WSS provides several standard controls to support navigation including the SiteMapPath control which populates a breadcrumb navigation menu to allow users to navigate from the current site upwards to the top-level site of current site collection. Navigation is based on the infrastructure provided by ASP.NET 2.0.

You can also create a custom master page template. To do this you must create the master page template itself, and then create a feature that provisions an instance of this master page in the Master Page gallery for a specific site. Finally you need to redirect site pages to use your custom master page instead of using default.master.

You can customized the look and feel of a site (brand it) by using Cascading Style Sheets.You can find standard language specific CSS files in \TEMPLATE\LAYOUTS\1033\STYLES.The primary file is called core.css. This file is scoped at farm level, so it is not a good idea to change it. Instead one way to change the look and feel is to use Themes which are found in TEMPLATE\THEMES.or we can create a custom.css file and put into TEMPLATE\LAYOUTS\1033\STYLES\<your folder>.Brand images are located in TEMPLATE\IMAGES

Keep writing!! 

Saturday, August 8, 2009

How to attach/delete/upload files to SharePoint List Item using Object Model

Hello Friends

I have one requirement in which I need to develop a web part in which users can upload multiple documents to SharePoint List Item and they can see all uploaded files into data grid control, they also need facility for user to delete selected files, add new files from same control and also they can download files.

Here in this post, I am writing code for each functionality as per my requirements.

Snippet code of deleting attachment from SharePoint list item :

private void DeleteAttachment(int NodeID, String strFileName)
    {
        try
        {
            SPContext.Current.Web.AllowUnsafeUpdates = true;

            SPListItem delItem = lstAudit.GetItemById(NodeID);
            SPAttachmentCollection atCol = delItem.Attachments;
            foreach (string strDelfileName in atCol)
            {
                if (strDelfileName == strFileName)
                {
                    atCol.Delete(strDelfileName);
                    delItem.Update();
                    lstAudit.Update();

                    return;
                }
            }

        }
        catch (Exception eDel)
        {
            string errDel = eDel.Message;
        }
    }
   

Snippet code for downloading attachment from SharePoint List Item :

 private void DownloadAttachment(string FileName)
    {
        try
        {
            string AttachmentURL = string.Empty;
            AttachmentURL = FileName;
            string strName = AttachmentURL.Substring(AttachmentURL.LastIndexOf("/") + 1);
            string sbURL = AttachmentURL.Trim();
            System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
            Response.AppendHeader("Content-disposition", "attachment; filename=" + strName);
            Response.AppendHeader("Pragma", "cache");
            Response.AppendHeader("Cache-control", "private");
            Response.WriteFile(sbURL);
            Response.End();
        }
        catch (Exception eDwn)
        {
            Response.Write(eDwn.Message);
        }
    }

Snippet code of uploading document to SharePoint List Item :

 protected void btnUpload_Click(object sender, EventArgs e)
    {
        try
        {
            string fileName = "";
            string strExtensionName = "";

            fileName = System.IO.Path.GetFileName(FileUpload.PostedFile.FileName);

            if (fileName != "")
            {
                strExtensionName = fileName.Substring(fileName.IndexOf(".") + 1);
                if (strExtensionName.Equals("webpart") || strExtensionName.Equals("dll") || strExtensionName.Equals("bat") || strExtensionName.Equals("exe"))
                {
                    lblMessage.Visible = true;
                    lblMessage.Text = "Invalid fileName!!";
                }
                else
                {
                    string _fileTime = DateTime.Now.ToFileTime().ToString();

                    string _fileorgPath = System.IO.Path.GetFullPath(FileUpload.PostedFile.FileName);

                    if (txtFileName.Text.Trim().Length > 0)
                    {
                        fileName = fileName.Replace(fileName.Substring(fileName.LastIndexOf("\\") + 1), txtFileName.Text) + "." + strExtensionName;
                    }
                    string _newfilePath = _fileTime + "~" + fileName;

                    string tempFolder = Environment.GetEnvironmentVariable("TEMP");

                   
                    string _filepath = tempFolder + _newfilePath;
                   
                    FileUpload.PostedFile.SaveAs(_filepath);

                    AddRow(fileName, _filepath, 0, true);
                }
            }
            else
            {

                lblMessage.Visible = true;
                lblMessage.Text = "Please Selct file Name";

            }

        }
        catch (Exception Ex)
        {
            Response.Write(Ex.Message);
        }

    }

   
    protected void dgdUpload_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int recordToDelete = e.RowIndex;

        //dt = (DataTable)Page.Session["Files"];
        dt = (DataTable)ViewState["Files"];

        int cn = dt.Rows.Count;

        if (Convert.ToInt32(dt.Rows[recordToDelete].ItemArray[0]) != 0)
        {
            DeleteAttachment(Convert.ToInt32(dt.Rows[recordToDelete].ItemArray[0]), dt.Rows[recordToDelete].ItemArray[1].ToString());
        }

        dt.Rows.RemoveAt(recordToDelete);

        dt.AcceptChanges();
        //Page.Session["Files"] = dt;
        ViewState["Files"] = dt;
        dgdUpload.DataSource = dt;
        dgdUpload.DataBind();
    }
    private void AddMoreColumns()
    {

        dt = new DataTable("Files");

        dc = new DataColumn("ID", Type.GetType("System.Int16"));
        dt.Columns.Add(dc);

        dc = new DataColumn("FileName", Type.GetType("System.String"));
        dt.Columns.Add(dc);

        dc = new DataColumn("FilePath", Type.GetType("System.String"));
        dt.Columns.Add(dc);

        //Page.Session["Files"] = dt;
        ViewState["Files"] = dt;

    }
    private void AddRow(string file, string path, int ID, Boolean bolCheckForfiles)
    {

        Boolean bolAddRow = true;
        //dt = (DataTable)Page.Session["Files"];
        dt = (DataTable)ViewState["Files"];
       
        if (dt == null)
        {
            AddMoreColumns();

        }
        if (bolCheckForfiles)
        {
       
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow drExistingrow in dt.Rows)
                {

                    if (drExistingrow["FileName"].ToString() == file)
                    {
                        bolAddRow = false;
                    }
                }
            }
        }
        if (bolAddRow)
        {

            dr = dt.NewRow();

 

            dr["ID"] = ID;
            dr["FileName"] = file;
            dr["FilePath"] = path;

 

            dt.Rows.Add(dr);

            //Page.Session["Files"] = dt;
            ViewState["Files"] = dt;

            dgdUpload.DataSource = dt;

            dgdUpload.DataBind();//bind in grid

        }
        else
        {
            lblMessage.Visible = true;
            lblMessage.Text = "Same File Name already exists!!!";
        }
    }

   
   

    protected void dgdUpload_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "View")
        {
            string file = e.CommandArgument.ToString();
            DownloadAttachment(file);

        }
    }

 

        if (dt != null)
        {

            int _dtcnt = dt.Rows.Count;
            foreach (DataRow dr in dt.Rows)
            {

                Boolean bolAddAttachment = true;
                fileName = dr["FileName"].ToString();
                if (itmCorrectiveActionFinding.Attachments.Count > 0)
                {
                    foreach (string strAttachedname in itmCorrectiveActionFinding.Attachments)
                    {

                        if (fileName == strAttachedname)
                        {
                            bolAddAttachment = false;

                        }
                    }
                }
                if (bolAddAttachment)
                {
                    string strFilepath = dr["FilePath"].ToString();

                    StreamReader sr = new StreamReader(strFilepath);

                    Stream fStream = sr.BaseStream;

                    contents = new byte[fStream.Length];

                    fStream.Read(contents, 0, (int)fStream.Length);

                    fStream.Close();

                    itmCorrectiveActionFinding.Attachments.Add(fileName, contents);

                    itmCorrectiveActionFinding.Update();
                    lstCorrectiveActionFinding.Update();
                    SPContext.Current.Web.Update();
                    System.IO.File.Delete(strFilepath);

                }
            }
        }

How to Integrate AJAX with Publishing SharePoint Site Templates

Hello Friends, 

When I have enabled AJAX with SharePoint into my site, I need to do lots of configuration changes into my site related to adding some new sections into web.config file, etc. 

This link is very useful; it’s giving us step by step instruction for how to integrate AJAX with SharePoint site.  

http://sharepoint.microsoft.com/blogs/mike/Lists/Posts/Post.aspx?ID=3 

But I have figured out that we need to make some more changes into master page in which we have publishing SharePoint site templates, Collaborate SharePoint site template

We need to open master page of Collaboration Site Template and need to add below lines. 

<BODY scroll=”yes”>

  <form runat=”server”>

 <WebPartPages:SPWebPartManager runat=”Server”/>

 <asp:ScriptManager runat=”server”></asp:ScriptManager> 

Hope it will help to someone! 

Thanks and Enjoy!!!

How to display detailed error messages into SharePoint page

It happens most of time with everyone when they are working with SharePoint and gets error message is “An unexpected error occurred”, that’s very boring and frustrated error message into SharePoint page, which leaves a number of guesses and questions. 

If you would like to know what exact error description is, then we need to make following changes into our SharePoint web application web.config file. 

1> CallStack=”false” changed to CallStack=”true” 

2> <customErrors mode=”On” /> changed to <customErrors mode=”Off” /> 

Happy debugging :)

Saturday, July 25, 2009

How to Send Email from SharePoint object model by accessing Email Configuration from Central Admin

Here is example code for sending email from SharePoint object model, main part of code would be “SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address”, it will return mail server address which is assigned from SharePoint central administration site as per web application

Sample Code:
,

private void SendEmail()
{
try
{
SmtpClient client = LoadSmtpInformation();
client.Send(BuildMailMessage());
}
catch (Exception Ex)
{
Response.Write(Ex.Message);
}
}

private SmtpClient LoadSmtpInformation()
{

string smtpServer = SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;
SmtpClient client = new SmtpClient(smtpServer);
client.UseDefaultCredentials = true;
return client;
}

private MailMessage BuildMailMessage()
{

MailMessage message = new MailMessage();

message.From = new MailAddress(SPContext.Current.Web.CurrentUser.Email);
message.To.Add(new MailAddress(User.Email));
message.IsBodyHtml = true;
message.Body = “Email Message”;

message.Subject = "Subject of Email";
return message;

}

Friday, July 24, 2009

How to write error message to SharePoint logs file

SharePoint object model gives us very good functionality and ability to write our customize error messages into SharePoint logs file.

We can pass our error string into LogString method from Microsoft.Office.Server.Diagnostics.PortalLog class and it will write error into logs file.

Sample Code:

try

{

//CODE

}

catch (Exception Ex)
{
Microsoft.Office.Server.Diagnostics.PortalLog.LogString("Exception – {0} – {1} – {2}" , "Sharepoint Application Name" , Ex.Message , Ex.StackTrace);

}

Catch the errors!!!

Monday, June 22, 2009

How to access fields of List Item in ItemAdding and ItemUpdating event handlers into SharePoint

When we need to validate something or put restriction before adding or modifying data, at that time we need to use ItemAdding or ItemUpdating Event Handler, here I’ll demonstrate how to access fields of List into event handlers.

Example:

As per my requirements, I don’t want to add duplicate Name into List. For this I need to check that condition before I add and update item to List, I need to use “ItemAdding” and “ItemUpdating” event handlers

public override void ItemAdding(SPItemEventProperties properties)
{
string strName = string.Empty;

foreach (DictionaryEntry entry in properties.AfterProperties)
{
if (entry.Key.Equals("Name"))
{
strName = entry.Value.ToString();
}
}

SPList list = properties.OpenWeb().Lists[properties.ListId];
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='" + list.Fields["Name"].InternalName + "' /><Value Type='Text'>" + strName + "</Value></Eq></Where>";
if (list.GetItems(query).Count > 0)
{
properties.Cancel = true;
properties.ErrorMessage ="Name already exists!";
}
}
public override void ItemUpdating(SPItemEventProperties properties)
{
string strName = string.Empty;
foreach (DictionaryEntry entry in properties.AfterProperties)
{
if (entry.Key.Equals("Name"))
{
strName = entry.Value.ToString();
}
}
SPList list = properties.OpenWeb().Lists[properties.ListId];
SPQuery query = new SPQuery();
query.Query=  "<Where><And><Neq><FieldRef Name='"+ list.Fields["ID"].InternalName+ "' /><Value Type='Number'>"+ properties.ListItemId+  "</Value></Neq><Eq><FieldRef Name='"+ list.Fields["Name"].InternalName+ "' /><Value Type='Text'>"+ strName+ "</Value></Eq></And></Where>" ;
if (list.GetItems(query).Count > 0)
{
properties.Cancel=true;
properties.ErrorMessage ="Name already exists!";
}
}