Saturday, August 22, 2009

How to create for Forms Authentication for SharePoint?

Create Database:
First step is to create membership database to save users and their credentials. To create membership database follow steps given below:
1. Open “%windir%\Microsoft.Net\Framework\vx.x.xxxxx” folder. Run aspnet_regsql.exe.
2. And complete the wizard steps(Select Configure SQL Server for application services option from the wizard).
3. Once wizard completed membership database has been created.

Configure Membership Providers:

This will allow us to add the users and roles into the database. To create user and role in database follow steps given below:
1. Create a new web site.
2. Add connection string in web.config file shown below

<connectionStrings>
<remove name="XX_ConnectionString" />
<add name="XX_ConnectionString"
connectionString="Integrated Security=SSPI;
Data Source=<SQLServerName>;Initial Catalog=<DatabaseName>;"
providerName="System.Data.SqlClient" />
</connectionStrings>

3. Now next specify the membership and role providers in the web.config file under <system.web> tag like shown below

<membership defaultProvider="XX_AspNetSqlMembershipProvider">
<providers>
<add connectionStringName="XX_ConnectionString"
passwordAttemptWindow="20"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
applicationName="/"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="1"
minRequiredNonalphanumericCharacters="0"
passwordStrengthRegularExpression=""
name="XX_AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider,System.Web,
Version = 2.0.0.0 ,
Culture = neutral,PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>

<roleManager enabled="true" defaultProvider="XX_AspNetSqlRoleProvider">
<providers>
<add connectionStringName="XX_ConnectionString"
applicationName="/"
name=”XX_AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider, System.Web,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>

4. Then used ASP.Net Configuration Wizard to create Role and Users.

MOSS People Picker cannot search Domain users

Why MOSS People Picker cannot search Domain users?
If you installed SQL server and SharePoint using local user account and not domain account, then if you are going to search domain users from the people picker, then domain user will not found from people picker.

Some work around for this:
1. Change user account for all app pool and services of SQL server and SharePoint with domain user account.
All App pool accounts(for central admin and other SharePoint web application)

2. Give access to the SharePoint database to new domain account as owner.

3. Update central admin farm credentials with new domain user account for this just need to run stsadm command.
stsadm -o updatefarmcredentials -identitytype configurableid -userlogin -password
This will update farm credentials.

4. Update SSP credentials with domain user account, Used stsadm command for change the SSP account credentails.
Stsadm.exe -o editssp -title "SSP Name" -ssplogin -ssppassword

This will update all necessary credentials for SharePoint farm, Then will get domain user from the people picker.

Saturday, June 27, 2009

How to wirte errors in EventViewer?

// logText will be the message to write in Event veiwer.
public static void WriteLog(string logText)
{

using (EventLog myLog = new EventLog("Application"))
{
// Create an EventLog instance and assign its source.
myLog.Source = "Application Name";

// Write an informational entry to the event log.
myLog.WriteEntry(logText, EventLogEntryType.Error);
}
}

Sunday, May 31, 2009

How to convert Image to Thumbnail image in C#?

//value is the fullsize image byte array
_fullLectureImage = (byte[])value;

System.Drawing.Image htmlImage = ByteArrayToImage(_fullLectureImage);
System.Drawing.Image thumnailImage = htmlImage.GetThumbnailImage(_imageWidth, _imageHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
this.Page.Session[_thumbnailImage] = ImageToByteArray(thumnailImage);


///
/// Returns System.Drawing.Image from byte array.
///

/// array of byte
/// System.Drawing.Image
private static System.Drawing.Image ByteArrayToImage(byte[] byteArrayIn)
{
MemoryStream memoryStream = new MemoryStream(byteArrayIn);
System.Drawing.Image returnImage = System.Drawing.Image.FromStream(memoryStream);
return returnImage;
}

///
/// Returns byte array from System.Drawing.Image.
///

/// System.Drawing.Image
/// array of byte
private static byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream memoryStream = new MemoryStream();
imageIn.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
return memoryStream.ToArray();
}

Wednesday, May 27, 2009

How to deploy web service on SharePoint site?

1. Create .asmx file and mark it as strong name.
2. Put the DLL into GAC.
3. Put .asmx file into LAYOUTS folder
4. Open the .asmx in notepad, remove the CodeBehind attribute and modify the class attributes as below
Class=", , Version=, Culture=, PublicKeyToken="
5. Run disco command from command prompt and we will get .disco and .wsdl files
6. Copy all the 3 files (asmx, .disco and .wsdl) to ISAPI folder.
7. Rename the .disco and .wsdl files to .aspx files. e.g. Rename the EMBS.disco to EBMSdisco.aspx
8. Access the url as
:/_vti_bin/.asmx">http://:/_vti_bin/.asmx
How to create .msi of WebApplication or WebSite and How to deploy it in IIS ?

1. Open the Web application project that you want to deploy.
2. Create New Project from select “Setup and Deployment Projects” à Web Set Up project. That will added Web Set Up project in same solution.
3. Select Web Application Folder in the left pane of the File System window.
4. Then,from the File menu select Add -> Existing Website to open the Add Existing WebSite Dialog box.Choose the Web Application that you want to Deploy.
5. Then right click on the “Web Application Folder” in the left pane of the File System window, and click add à Project Output menu, that will open dialog “Add project Output group”, then select content Files and click ok.
6. Then build the solution. That will create the .msi in the Debug directory of the Web Setup project.
7. Run the .mis file on any server to Deploy your WebSite or WebApplication.
How to convert website to webapplication in .NET?

Consider you have Solution and website is exist in that solution then
1. Added WebApplication project in existing solution. (That you have one website and one WebApplication in that solution)
2. Copy all files from website to webApplication with keep same structure as website.
3. Then right click on the webApplication and click on “Convert to Web Application“. That will add .designer.cs file for all .aspx pages and ascx pages.
4. Add namespace to all .aspx and .ascx files. (namespace will add in .aspx file in Inherits attribute of page dirsctive, .aspx.cs and .designer.cs file)
5. Then delete website from that solution.

And your webApplication will created.