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

Membership Provider entries in web.config

April 11, 2009 Sunil Yadav Leave a comment

Following are the setting you need to do in web.config for your Membership Provider.

<add name="Sqlconstring" Data Source="SQLServerInstance\SQLEXPRESS";Initial Catalog=Database Name;Integrated Security=True" System.Data.SqlClient"/>
</connectionStrings/>

<membership>
<providers>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="Sqlconstring"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
applicationName="application name"
passwordFormat="Hashed"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1"
passwordAttemptWindow="10"
passwordStrengthRegularExpression="">
</providers>
</membership>
Categories: ASP.Net

Difference between Application caching and session objects

April 10, 2009 Sunil Yadav Leave a comment

Session
A session is the time for which a particular user interacts with a web   application.  During a session the unique identity of the user is maintained  internally. A  session ends if there is a session timeout or user ends sessionby logging out.Sessions may change from user to user.

Cache
Caching can be used to temporarily store page output or application data either on the client or on the server,  which can then be re-used to satisfy subsequent requests and thus avoid the overhead of re-creating the same  information.Caching is particularly suitable when you expect to  Cache will be applicable to the entire application through out it’s life cycle return the same information in the same format for many different requests.

Application
Its nothing but similar to Session with a bit difference that is Session objects have scope within a particular session while application  objects having scope within entire application.  Application are accessible only from code running within the context of the originating application. Other applications running on the system cannot access or modify the values.

Categories: ASP.Net

Why we should avoid opening links in new window.

Hi,

1.you should avoid forcing links to open in a new window or pop ups using JavaScript as you might know Java Script is not supported by all browsers or some users might disable it.

2.Opening a link in a new window also breaks the back button on the browser, so you won’t be able to track navigation.

3.Opening link in a new window is almost supported by all browser so its better to let user decide weather to open a new window or not.

4.web users are likely to expect the new page to load in the current window so opening a new window might be surprise for them , also there are some cases when opened window lost like (while pressing ALT+TAB) so user wont be able  to know which window is opened.

But there are situation when we need to open link in new window like ….

The link is for a document, such as a PDF or a Word document or image file which is large in size so the document or image will download in the background and user will browse the site without any pause.

Categories: ASP.Net