Monday, 10 November 2014

Microsoft Windows

\\SystemName\ c$ To access C drive
\\SystemName\ d$ To access D drive
\\SystemName\ e$ To access E drive
==========================================
Services
--------
MOSS 2007
Windows SharePoint Services Administration
Windows SharePoint Services Search
Windows SharePoint Services VSS Writer
SQL
SQL Server Browser
SQL Server (MSSQLSERVER)
==========================================
ildasm.exe
C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin
machine.config
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG
aspnet_regsql.exe
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
==========================================
Sharepoint Log
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\LOGS
====================================================================================
MSTSC
Login as Admin and Kill other user accounts
mstsc -v:SERVER /f -admin
====================================================================================
Managing event logs from the command line
Run-->eventvwr.exe
or
Start-->control panel-->Administrative Tools-->Event Viewer
====================================================================================
Service
Run-->services.msc
Or
Start-->control panel-->Administrative Tools-->Services

Add user custom action to Site Actions menu using Client Object Model


C# Get Set Properties

Sharepoint Custom Workflow

// Method used to get the SharePoint List that the workflow is attached to and the list item that we are working on
private void getTaskListInformation()
{
// Get the Task List that we are attached to, by converting the Guid Parameter into a Guid
this._TaskListAttachedTo = this._myTeamSite.Lists[new Guid(this._paramSPListGuid)];
// Get the Task Item Object that the workflow has created
this._TaskListItem = this._TaskListAttachedTo.GetItemById(System.Convert.ToInt16(this._paramTaskListItemID));
string[] passedLink = _TaskListItem["Link"].ToString().Split(',');
listID = Convert.ToInt32(passedLink[0].Split('=')[1]); // Get the application request ID.
// Get the ID of the Workflow Instance that we are running with in
this._workflowInstanceGuid = new Guid(Convert.ToString(this._TaskListItem["WorkflowInstanceID"]));
// Instantiate the workflow
this._activeWorkflow = new SPWorkflow(this._TaskListItem, this._workflowInstanceGuid);
}
=============================
private void getTaskListInformationByListItem()
{
listID = Convert.ToInt32(Request.Params["ID"]);
SPSite site = SPContext.Current.Site;
using (SPWeb web = site.OpenWeb())
{
SPList JobRequest = this._myTeamSite.Lists["Request"];
SPListItem JobRequestItem = null;
if (listID > 0)
{
JobRequestItem = JobRequest.GetItemById(listID);
}
if (JobRequestItem != null)
{
SPListItemCollection taskListItems = JobRequestItem.Workflows[0].TaskList.Items;
foreach (SPListItem item in taskListItems)
{
string[] passedLink = item["Link"].ToString().Split(',');
if (Convert.ToString(item["Status"]) == "Not Started") // Get the Application request ID.
{
// Get the Task List that we are attached to, by converting the Guid Parameter into a Guid
this._TaskListAttachedTo = this._myTeamSite.Lists["Tasks"];
// Get the Task Item Object that the workflow has created
this._TaskListItem = this._TaskListAttachedTo.GetItemById(item.ID);
// Get the ID of the Workflow Instance that we are running with in
this._workflowInstanceGuid = new Guid(Convert.ToString(this._TaskListItem["WorkflowInstanceID"]));
// Instantiate the workflow
this._activeWorkflow = new SPWorkflow(this._TaskListItem, this._workflowInstanceGuid);
}
}
}
}
}
==================================================================
// Code that responds to the Reject Button Click event.
protected void btnReject_Click(object sender, EventArgs e)
{
if (isValid())
{
Hashtable taskHash = new Hashtable(); // Task data is sent via a Hash Table
taskHash["_ApporvalStatus"] = false;
taskHash["Status"] = "Complete";
taskHash["PercentComplete"] = "0";
taskHash["Action"] = "Rejected";
SPSite site = SPContext.Current.Site;
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWorkflowTask.AlterTask(this._TaskListItem, taskHash, true); // Send the data to the task list, by altering the tasks value
});
web.AllowUnsafeUpdates = false;
}
string strRequestorRole = this._TaskListItem.Title;
UpdateAuditTrail("Rejected", strRequestorRole.Replace(" Task", ""));
SPUtility.Redirect(this._TaskListAttachedTo.DefaultViewUrl, // Redirect the UI back to the Task List. You could chose
SPRedirectFlags.UseSource,
HttpContext.Current);
}
}
==============================================================================
// Code that responds to the Cancel Button Click event.
protected void btnCancel_Click(object sender, EventArgs e)
{
// If the user cancels out on the Workflow Task Edit Form, we'll take them back to the Document Library
if (this._TaskListAttachedTo == null)
{
SPUtility.Redirect(this._myTeamSite.Url,
SPRedirectFlags.UseSource,
HttpContext.Current);
}
else
{
SPUtility.Redirect(this._TaskListAttachedTo.DefaultViewUrl,
SPRedirectFlags.UseSource,
HttpContext.Current);
}
}
=========================================================================
// Code that responds to the Accept Button Click event.
protected void btnAccept_Click(object sender, EventArgs e)
{
SPSite site = SPContext.Current.Site;
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
int statusID = GetLookupId("Accepted", "Title", "JobRequestStatus");
SPList JobRequestListItems = web.Lists["Request"];
SPListItem requestItem = JobRequestListItems.GetItemById(listID);
requestItem["Status"] = new SPFieldLookupValue(statusID, "Accepted");
requestItem["Scheduler"] = Request.ServerVariables["LOGON_USER"].ToString();
requestItem.Update();
web.AllowUnsafeUpdates = false;
}
// If the user cancels out on the Workflow Task Edit Form, we'll take them back to the Document Library
SPUtility.Redirect(this._TaskListAttachedTo.DefaultViewUrl,
SPRedirectFlags.UseSource,
HttpContext.Current);
}

issue while installation K2 Blackpearl

If you are getting any issue while installation if you get any issue please check whether below things are installed or not.
SharePoint Server 2007 SP2 64bit (one server - Windows Server 2003 R2 SP2 64bit)
SQL Server 2005 SP2 32bit (one server - Windows Server 2003 SP2 32bit)
1.All necessary additional software and windows components are installed
Ex: com+, MSMQ, MS Redist, DTC installed and configured
2.Kerberos is activated for the SharePoint Portal Web Application
3.DNS entries, host header and SPNs are set correctly (no duplicate entries)
4.Permissions for k2 service accounts are set correctly (farm admin, site collection admin, sql admin)

Coding Standards

Namespaces:
Remove the unused namespaces and separate the Asp.Net framework namespaces with third party or other frame work spaces as below.
This makes the identification of namespaces at first look itself.
Always use Response. Redirect with false as its second parameter value
Response.Redirect("Response.aspx?ErrorID=1000",false);
Conditions Format
if (!(Session["FullName"] == null))
Use the below format for better readability
if (Session["FullName"] != null)
String Conversion not required on control’s text values
if (!string.IsNullOrEmpty(txtComment.Text.ToString().Trim()))
{
}
txtComment.Text itslef will return the string value and again don’t need to convert that value using ToString() method this looks odd, pleease remove this.
Use Page.IsValid property under submit/resubmit event handlers
if (Page.IsValid)
{
//Show some message to the user saying the validations are not met on page/ show validation summary control
return;
}
This helps avoiding the unexpected behavior of pages when validations are not firing because of JavaScript errors.
Add sub functions for main functions
If possible try to reduce the no’ of lines of code for each function by diving the functionality into sub functions (common logic).
Exception rising
catch (Exception ex)
{
//objCommonMethods.GenericExceptionMethod(ex);
spnErrorMsg.Visible = true;
objCommonMethods.DisplayMessage(this.spnErrorMsg, "Error", "Error Occured While Page Loading.");
}
Here we are not sowing the actual exception; this will not help in trouble shooting the issues in production. So please add the inner exception message to the display message.
catch (Exception ex)
{
//objCommonMethods.GenericExceptionMethod(ex);
spnErrorMsg.Visible = true;
objCommonMethods.DisplayMessage(this.spnErrorMsg, "Error", "Error Occured While Page Loading." + ”
” ex.Message +”
” + ex.StackTrace);
}
ex.StackTrace will give us the line number of code which is throwing the exception.
When throwing exception use the below format:
catch (Exception ex)
{
// throw ex;
throw new Exception("Exception in GetApprovers method", ex);
}
Use StringBuilder over strings when string concatenation is required more than 2 levels:
Use length condition before using string remove methods ***
Remove web related and unused namespaces in class files.
For string comparison use string.Compare()
With comparison method:
if (string.Compare(CompairFile.Trim(),InFile.Trim(),false) == 0)
{
file.Delete();
break;
}
Remove the commented code in all the files
Use count condition check before using a list enumeration in foreach loop
Ex:
foreach (DataRow drRole in dsApprovers.Tables[0].Rows)
{}
If the dsApprovers.Tables[0] doesn’t have any rows, it throws an exception.
Please check the for the same in other places.
Use DataTables over Datasets
For functions we are using Dataset in many places, but I think it will make sense when we use Data Table directly. Usually we use Dataset when we fill multi table’s data with relation. In our case we are nowhere storing multiple tables into Dataset. So using Data Tables is suggestible.
Move all the connection strings and constant values those are coming form web.config file can be moved to CommonConstantVariables class and can be made them static properties
Make Page level viewstate and session false for static pages like Response.aspx, confirmation.aspx and Unauthorized.aspx. This helps the pages load faster.
Example:

SharePoint Apply Branding using Feature


Apply Branding using Feature

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
Add a class
public class ApplyBranding : SPFeatureReceiver
{
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = (SPWeb)properties.Feature.Parent;
using (SPSite site = new SPSite(web.Url))
{
using (SPWeb rootWeb = site.RootWeb)
{
string serverRelativeUrl = rootWeb.ServerRelativeUrl;
string masterUrl = getPropertyFrom(properties, "MasterUrl");
string customMasterUrl = getPropertyFrom(properties, "CustomMasterUrl");
string alternateCssUrl = getPropertyFrom(properties, "AlternateCssUrl");
string siteLogoUrl = getPropertyFrom(properties, "SiteLogoUrl");
string theme = getPropertyFrom(properties, "Theme");
bool isMySite = getPropertyFrom(properties, "IsMySite").Equals("TRUE", StringComparison.InvariantCultureIgnoreCase);
if (serverRelativeUrl != "/" && !isMySite)
{
masterUrl = mergeUrls(serverRelativeUrl, masterUrl);
customMasterUrl = mergeUrls(serverRelativeUrl, customMasterUrl);
alternateCssUrl = mergeUrls(serverRelativeUrl, alternateCssUrl);
}
saveOldBranding(web);
applyBranding(web, masterUrl, customMasterUrl, alternateCssUrl, siteLogoUrl, theme, isMySite);
}
}
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPWeb web = (SPWeb)properties.Feature.Parent;
bool isMySite = getPropertyFrom(properties, "IsMySite").Equals("TRUE", StringComparison.InvariantCultureIgnoreCase);
if (!isMySite)
{
resetBranding(web);
}
else
{
string masterUrl = "default.master";
string customMasterUrl = "default.master";
string alternateCssUrl = "";
string siteLogoUrl = "";
string theme = "";
web.Properties.Update();
applyBranding(web, masterUrl, customMasterUrl, alternateCssUrl, siteLogoUrl, theme, isMySite);
}
}
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{ }
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
SPWeb web = (SPWeb)properties.Feature.Parent;
string masterUrl = removeFromwebProperties(web, "BrightstarrBrandingMasterPageUrl");
string customMasterUrl = removeFromwebProperties(web, "BrightstarrBrandingCustomMasterUrl");
string alternateCssUrl = removeFromwebProperties(web, "BrightstarrBrandingAlternateCssUrl");
string siteLogoUrl = removeFromwebProperties(web, "BrightstarrBrandingSiteLogoUrl");
string theme = removeFromwebProperties(web, "BrightstarrBrandingTheme");
web.Properties.Update();
web.Update();
}
private string getPropertyFrom(SPFeatureReceiverProperties properties, string key)
{
string propertyValue = string.Empty;
try
{
propertyValue = properties.Feature.Definition.Properties[key].Value;
}
catch
{ }
return propertyValue;
}
private void saveOldBranding(SPWeb web)
{
saveToWebProperties(web, "BrightstarrBrandingMasterPageUrl", web.MasterUrl);
saveToWebProperties(web, "BrightstarrBrandingCustomMasterUrl", web.CustomMasterUrl);
saveToWebProperties(web, "BrightstarrBrandingAlternateCssUrl", web.AlternateCssUrl);
saveToWebProperties(web, "BrightstarrBrandingSiteLogoUrl", web.SiteLogoUrl);
saveToWebProperties(web, "BrightstarrBrandingTheme", web.Theme);
web.Properties.Update();
}
private void saveToWebProperties(SPWeb web, string key, string value)
{
saveToWebProperties(web, key, value, false);
}
private void saveToWebProperties(SPWeb web, string key, string value, bool update)
{
if (!web.Properties.ContainsKey(key))
web.Properties.Add(key, value);
if (update)
web.Properties.Update();
}
private void applyBranding(SPWeb web, string masterPageUrl, string customMasterUrl, string alternateCssUrl, string siteLogoUrl, string theme)
{
applyBranding(web, masterPageUrl, customMasterUrl, alternateCssUrl, siteLogoUrl, theme, false);
}
private void
applyBranding(SPWeb web, string masterPageUrl, string customMasterUrl, string alternateCssUrl, string siteLogoUrl, string theme, bool isMySite)
{
if (!string.IsNullOrEmpty(masterPageUrl))
{
if (isMySite)
{
if (web.MasterUrl.Contains("default.master"))
{
web.MasterUrl = web.MasterUrl.Replace("default.master", masterPageUrl);
}
else
{
web.MasterUrl = web.MasterUrl.Replace(masterPageUrl, "default.master");
}
}
else
web.MasterUrl = masterPageUrl;
}
if (!string.IsNullOrEmpty(customMasterUrl))
{
if (isMySite)
{
if (web.CustomMasterUrl.Contains("default.master"))
{
web.CustomMasterUrl = web.CustomMasterUrl.Replace("default.master", customMasterUrl);
}
else
{
web.CustomMasterUrl = web.CustomMasterUrl.Replace(customMasterUrl, "default.master");
}
}
else
web.CustomMasterUrl = customMasterUrl;
}
web.AlternateCssUrl = alternateCssUrl;
web.SiteLogoUrl = siteLogoUrl;
web.ApplyTheme(theme);
web.Update();
}
private void resetBranding(SPWeb web)
{
string masterUrl = fetchFromwebProperties(web, "BrightstarrBrandingMasterPageUrl");
string customMasterUrl = fetchFromwebProperties(web, "BrightstarrBrandingCustomMasterUrl");
string alternateCssUrl = fetchFromwebProperties(web, "BrightstarrBrandingAlternateCssUrl");
string siteLogoUrl = fetchFromwebProperties(web, "BrightstarrBrandingSiteLogoUrl");
string theme = fetchFromwebProperties(web, "BrightstarrBrandingTheme");
applyBranding(web, masterUrl, customMasterUrl, alternateCssUrl, siteLogoUrl, theme);
}
private string removeFromwebProperties(SPWeb web, string key)
{
return removeFromwebProperties(web, key, false);
}
private string removeFromwebProperties(SPWeb web, string key, bool update)
{
string returnValue = string.Empty;
if (web.Properties.ContainsKey(key))
{
returnValue = web.Properties[key];
web.Properties.Remove(key);
}
if (update)
web.Update();
return returnValue;
}
private string fetchFromwebProperties(SPWeb web, string key)
{
string returnValue = string.Empty;
if (web.Properties.ContainsKey(key))
{
returnValue = web.Properties[key];
}
return returnValue;
}
private string mergeUrls(string serverUrl, string relativeUrl)
{
string returnUrl = serverUrl;
if (!serverUrl.EndsWith("/"))
returnUrl = serverUrl + "/";
if (relativeUrl.Length > 1)
{
if (relativeUrl.StartsWith("/"))
relativeUrl = relativeUrl.Substring(1);
returnUrl = returnUrl + relativeUrl;
}
return returnUrl;
}
}