Archive

Author Archive

Add user to SharePoint Sites using stsadm command

December 10, 2009 Sunil Yadav Leave a comment

Following is the way to add user to sharepoint site using stsadm command.

stsadm -o adduser -url http://mossportal:2020 -userlogin Username -useremail user1234@domain.com -group “Farm Administrators” -username “Administrators”

Categories: Sharepoint

File exist error in sharepoint.

December 10, 2009 Sunil Yadav Leave a comment

Recently i came across an issue when I tried to login to my SharePoint intranet portal.

The file exists. (Exception from HRESULT: 0×80070050).

After playing around it for around 3-4 hours I got the solution.
This error occurred when I moved my local system to the domain. When you moved your local system to the domain, all the local user policy is replaced by domain user policy. In my case local administrator account was deleted which doesn’t happens generally. This can also happen when you delete the account which is used during SharePoint installation. It’s bad idea to move your machine on domain after installing SharePoint server or deleting user account responsible for installing SharePoint.

One common mistake made when installing SharePoint for the first time, is using a personal administrator account when installing. The reason for not wanting to use a personal administrator account is the account used when installing SharePoint is given special rights on the server. It has been found in extreme instances of troubleshooting that the only account able to complete the configuration wizard to detach from a corrupted farm is the account initially used to install SharePoint. To avoid this issue, a SharePoint Admin account can be created and used for installations. Prior to installation, this account should be given administrator rights on all SharePoint servers and should be given the SQL Server dbcreator and securityadmin roles. The minimalist approach involves creating two accounts, one to run and manage SharePoint and the other to manage Search.

Since the account has not sufficient rights (db owner) on the database named “WSS_Content” and “Admin_content”.
We need to add user to the “WSS_Content” and “Admin_content” databases in SQL with DB_Owner and Security Admin roles.

sp_addrolemember ‘db_owner’,'Username’
sp_addrolemember ‘db_securityadmin’,'Username’

Also we need to add user to the sharepoint site.

stsadm -o adduser -url http://mossportal:2020 -userlogin Username -useremail user1234@domain.com -group “Farm Administrators” -username “Administrators”

When you install windows server 2003/2008, Windows generate SID for users and assign unique SID for them. When you install SharePoint on your machine, SharePoint adds user’s information like SID, user’s Site ID, and permissions in the SharePoint database. Also when browsing site SharePoint users SID and SID stores in database are compared and based on this it authorizes user. Since both SID’s were different it is likely that SharePoint will be affected. We cannot change SID for the user so we have to change SID stored in the database.
Following is the way to change/update the SID stored in the database.
Select the database which needs to be update SID entry. In my case it was in Wss_content and SharePoint_AdminContent.
Here you will get all user related information on selected database.

SELECT *
FROM UserInfo
WHERE tp_Login=’username’

‘username’ is user account which got deleted.
Above query shows SID for selected username. Now we need to find SID for the same user in the Windows and replace it with database SID. You can use PStools utility and execute the command on command prompt “Psgetsid username“to get user SID.
This command’s result for my machine shown in image:
For example my administrator’s SID is:
S-1-5-21-1422252240-1001139268-3133179427
Here we need to convert SID into hex format as follows:

0x =0x
S-1=01
5 = 0×000000000005=000000000005
21 =15000000
1422252240=D0D8C554 (hexadecimal of 1422252240=54C5D8D0 and little endian of 54C5D8D0=D0D8C554)
1001139268=442CAC3B (same way as above)
3133179427=2386C0BA (same way as above)
500=F4010000 (same as above)
And Hex format of SID:
0×010500000000000515000000D0D8C554442CAC3B2386C0BAF4010000

Now you should to update database table with new SID. Run the following query in sql server management studio.

UPDATE UserInfo SET tp_SystemID = cast(‘0×0105000000000005150000000D8D5C4544C2CAB332680CABF4010000′ as varbinary) FROM UserInfo WHERE tp_ID = ‘1′ tp_Login=’username’ and tp_SiteID =’FDDA95A1-3B15-46B5-801C-2101ACC6B7F8′

That’s all …..Your site should now up and running.

Categories: Sharepoint Tags:

The search request was unable to connect to the Search Service

December 9, 2009 Sunil Yadav Leave a comment

Recently i came across the issue “The search request was unable to connect to the Search Service”.

After the usual troubleshooting i found solution.There are many solution

1.Go to Start
2.select Run
3.Type in “Services.msc”
4.In the services console check wheather Windows SharePoint Services Search(ONLY IF THAT SERVER IS MANAGING YOUR SEARCH) is running.

1.Goto Computer management
2.Select Services and applications
3.Start indexing service.

Restart “Office SharePoint Server Search(ONLY IF THAT SERVER IS MANAGING YOUR SEARCH) ” and “Windows SharePoint Services Search (ONLY IF THAT SERVER IS MANAGING YOUR SEARCH) ” Windows Services

1.Go to Operations tab in Central Administration
2.Select “Services on Server” from Topology and Services
3.Select your Indexing/application Server from the server menu and make sure “Office SharePoint Server Search” and “Windows SharePoint Services Search” services are started.

1.Go to Central Administration

2.Select Operations Tab

3.Select Services on Server

4.check whether Office Share Point Server Search is started.

Search the Application Pool that is using Microsoft SharePoint Server, change
the permissions from Network Services to an account that having sufficient
privileges to access the SQL Database.

Another possible resolution could be that the user who is configured to run the search has not the required permissions. So check the user permission on the SQL Database. And if your SQL Server is running under Mixed Mode Authentication.

When the Index and Query roles are installed on different Web servers, check whether for ports of index and query servers are opened.

Failed to register SharePoint Services

November 9, 2009 Sunil Yadav Leave a comment

Recently When I was trying to run Configuration Sharepoint Product and Technologies after successful installation of MOSS 2007 sp1, I was getting error “Failed to register SharePoint Services”.After googling for more than 1 hour i found solution.

Solution.

1. Open regedit.

2. In the Registry Editor, navigate to the following subkey “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\WSS\Services” and delete the entry “Microsoft.Office.Server.Search.Administration.SearchService”.

3. Run the SharePoint Products and Technologies Configuration Wizard again.

Categories: Sharepoint

Create or extend Web application option missing from SharePoint Central Administration site

November 9, 2009 Sunil Yadav Leave a comment

Recently I wanted to create a new web application in SharePoint 2007 and so I went to the Central Administration site to create one, but the option “Create or extend Web application” was missing.So after playing around it for 2-3 hours i notice the cause of the problem.It was permission related issue.
So i run “Central Administration” site with administrator privileges (run Internet Explorer as Administrator) .Also i have added to “Central Administration” site to the intranet zone.
Now, I am able to see the “Create or extend Web application” options.

Categories: Sharepoint

Modifying Created By and Modified By column in sharepoint list

October 23, 2009 Sunil Yadav Leave a comment

Created by and Modified By are system default columns.You cannot directly edit Created by or Modified By column in sharepoint out of box. All you need to do is make the column display in your view

Following is one of the way to modify these two columns..

SPSite site = new SPSite("http://intranet");
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPList list = web.Lists["User Details"];
SPListItemCollection collection = list.Items;
foreach (SPListItem item in collection)
{
SPUser user = web.EnsureUser(@"intranet\Administrator");
item["Created By"] = @"intranet\sunil"; // Created By field
item.Update();
}
list.Update();
web.Update();
web.Close();
Categories: Sharepoint

Developing Sequential Workflow In ASP.Net Applications

October 16, 2009 Sunil Yadav Leave a comment

In this article i am going to explain how to create sequential workflow in asp.net.

step:1 ->;; Create New Sequential Workflow Project

Open Visual Studio 2008 –>; create a new project–>; Choose  Sequential Workflow Library

New Workflow

New Workflow

at this point,the workflow project contains single workflow class(workflow1).

step:2 ->;  Drag a IfElse activity onto the design surface from  the toolbox.The designer looks like below figure below.

New Workflow

Note that while dragging activity on the surface you will see  green (+ sign) which indicates a place where you can drop activity.(you can also refer figure below).
step:3 -> Drop Code activity inside ifElseBranchActivity1 and ifElseBranchActivity2 and name them as Authorized and UnAuthorized respectively.

New Workflow

step:4 -> set the Condition on ifElseBranchActivity1 to  code condition and set the condition property to IsAuthorized.

private void IsAuthorized(object sender, ConditionalEventArgs e)
{
if (UserName == "sunil" && Password == "demo@123")
{
this.Result = "Welcome.aspx";
}
else
{
this.Result = "NotAuthorized.aspx";
}
}

Also create following to accept parameter value..

public string UserName { get; set; }
public string Password { get; set; }
public string Result { get; set; }

step:5 ->; Create asp.net application in the solution, add to more page Welcome.aspx and UnAuthorized.aspx i the application as shown below

New Workflow

Write down the following code on Login_Click.

protected void Login_Click(object sender, EventArgs e)
{
WorkflowRuntime wr = new WorkflowRuntime();

wr.AddService(new ManualWorkflowSchedulerService());
Dictionary parameters = new Dictionary();
parameters.Add("Result", "");
parameters.Add("UserName", txtUserName.Text);
parameters.Add("Password", txtPassword.Text);
wr.WorkflowCompleted += new EventHandler(wfRuntime_WorkflowCompleted);
WorkflowInstance wi = wr.CreateWorkflow(typeof(SequentialWorkflowDemo.Workflow1), parameters);
wi.Start();
ManualWorkflowSchedulerService ss = wr.GetService();
ss.RunWorkflow(wi.InstanceId);
}

also following line of code to redirect user to specific page.

void wfRuntime_WorkflowCompleted(object sender, WorkflowCompletedEventArgs e)
{
HttpContext.Current.Response.Redirect((string)e.OutputParameters["Result"]);
}

Your workflow application is ready to execute.Run your asp.net application.

Categories: Workflow

Http handlers to handle images

September 4, 2009 Sunil Yadav Leave a comment

In this article i am going to create a Http Handler which will be used to resize images .

What are HTTP Handler

HTTP handlers are the .NET components that implement the System.Web.IHttpHandler interface, they can act as a target for the incoming HTTP requests and can be called directly by using their file name in the URL.
HTTP handlers implement the following two methods:
1) ProcessRequest: called to process http requests and
2) IsReusable which indicates whether this instance of http handler can be reused for fulfilling another requests of the same type.

Right click on your website–> Add new Item–> Generic Handler and name it as ImageHandler.ashx

Here is ImageHandler.ashx file

<%@ WebHandler Language="C#" %>

using System;
using System.Web;
using System.IO;

public class ImageHandler : IHttpHandler
{
 public void ProcessRequest(HttpContext context)
{
string sImageFileName = "";
int iThumbSize = 0;
decimal dHeight, dWidth, dNewHeight, dNewWidth;

sImageFileName = context.Request.QueryString["img"];
iThumbSize = Convert.ToInt32(context.Request.QueryString["sz"]);</span></p>
System.Drawing.Image objImage = System.Drawing.Bitmap.FromFile(System.Web.HttpContext.Current.Server.MapPath("Image Path" + sImageFileName));
if (sImageFileName != null)
{
if (iThumbSize == 1)
{
dHeight = objImage.Height;
dWidth = objImage.Width;
dNewHeight = 120;
dNewWidth = dWidth * (dNewHeight / dHeight);
objImage = objImage.GetThumbnailImage((int)dNewWidth, (int)dNewHeight, new System.Drawing.Image.GetThumbnailImageAbort(callback), new IntPtr());
}
if (iThumbSize == 2)
{
dHeight = objImage.Height;
dWidth = objImage.Width;
dNewHeight = 200;
dNewWidth = dWidth * (dNewHeight / dHeight);
objImage = objImage.GetThumbnailImage((int)dNewWidth, (int)dNewHeight, new System.Drawing.Image.GetThumbnailImageAbort(callback), new IntPtr());
}

MemoryStream objMemoryStream = new MemoryStream();
objImage.Save(objMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] imageContent = new byte[objMemoryStream.Length];
objMemoryStream.Position = 0;
objMemoryStream.Read(imageContent, 0, (int)objMemoryStream.Length);
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(imageContent);
}
}
 private bool callback()
{
return true;
}
public bool IsReusable
{
get
{
return false;
}
}

}

Following is the way to write it..

<img id="Image1"  src='../ImageHandler.ashx?img=ImageName&amp;sz=1' />

Why to use StoredProcedures ?

April 15, 2009 Sunil Yadav 2 comments

Stored Procedures can be reused from different webpages, classes or webapplication where in case of coding sql statements you have to write code in each and every place.

Stored Procedures uses parameters to receive user input values so helps to prevent SQL injection.

Stored procedure are in complied form i.e they are already in compiled mode you nedd need to call them in your application. wherein when you write sql query the processor has to parse it, analyze it and execute it. so the stored procedure are faster than coding sql queries.

Stored Procedures are easy to debug.

Also from security point of view we can provide credentials to execute the stored procedure so this means that users access to the database can be defined by only allowing them permissions to execute the allowed stored procedures while denying them permissions to the underlying database objects such as tables and views that are used by the stored procedures.

Categories: SQL Server 2005/08

Logging Errors and Exceptions in ASP.NET 2.0

April 12, 2009 Sunil Yadav Leave a comment

In this article i am going to use simple class which use to write error and exceptions occured in your asp.net application in a text file format.

Below i have created a class Common in which there is function WriteToEventLog which accepts Exception as parameter.

public class  Common

{

public static void WriteToEventLog(Exception exception)
{
string sPath = "~/error/" + DateTime.Today.ToString("dd-mm-yy") + ".txt";
if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(sPath)))
{
File.Create(System.Web.HttpContext.Current.Server.MapPath(sPath)).Close();
}

StreamWriter objStreamWriter = File.AppendText(System.Web.HttpContext.Current.Server.MapPath(sPath));
{
objStreamWriter.WriteLine("\r\nLog Entry : ");
objStreamWriter.WriteLine("{0}", DateTime.Now.ToString(CultureInfo.InvariantCulture));
string sError = "Error in: " + System.Web.HttpContext.Current.Request.Url.ToString() +
". Error Message:\n" + exception.Message;
objStreamWriter.WriteLine(sError);
objStreamWriter.WriteLine("__________________________");
objStreamWriter.Flush();
objStreamWriter.Close();
}
}

}

Now our class is ready you only need to call in your try catch body as shown below…

protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
if (User.HasUserLoggedIn())
{

UpdateTotal();
}
else
{
Response.Redirect("~/pages/MessagePage.aspx?ConfigValue=MsgUserNotLoggedIn", false);
}
}
}
catch (Exception ex)
{
Common.WriteToEventLog(ex);
}
}
Categories: ASP.Net