Friday, October 2, 2009

Some helpful STSADM command

Some helpful STSADM command

----Starting Service MSSQLServer...
NET START "SQL Server (MSSQLServer)"

----ECHO Resetting IIS...
"C:\WINDOWS\system32\iisreset.exe"

----Creating Roles and Membership database...
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql" -S <SQL Server Name> -E -d "<DB Name>" -A all

----Copying **** config file
CD C:\Vinod\folder1
COPY /Y ****.xml "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG"


----Installing and activating
STSADM -o activateFeature -filename *\feature.xml -url <Web app URL with Port> -force
----Deploy *.wsp solution package
--First adding solution package to farm...
STSADM -o addsolution -filename C:\folder1\*.wsp

--Deploying solution package to http://<MACHINENAME>:<CENTRALPORT> site... STSADM -o deploysolution -name *.wsp -url http://<MACHINENAME>:<CENTRALPORT> - allowgacdeployment -immediate -force

--STOP timers if any
STSADM -o execadmsvcjobs

--Error adding WSP Package; attempting upgrade instead
STSADM -o upgradesolution -filename C:\folder1\*.wsp -immediate -allowgacdeployment -allowcaspolicies

--STOP timers if any
stsadm -o execadmsvcjobs

----Adding Template
stsadm -o addtemplate -filename C:\folder1\TEMPLATE1.stp -Title "<TEMPLATENAME>"

----Create SSP
STSADM -o createssp -title "<SSP Title>" -url <SSP URL With PORT> -mysiteurl <MySite URL With PORT> -ssplogin <Domain Name>\<User ID> -ssppassword <Password> -indexserver <SQL Server name> -indexlocation "C:\Program Files\Microsoft Office Servers\12.0\Data\Office Server\SSPIndexes" -sspdatabasename <SSP DB Name> -searchdatabasename <SSP DB Name>

----Starting Office SharePoint Server Search...
STSADM -o osearch -action start -f -role IndexQuery -farmcontactemail <User Email ID> -farmserviceaccount <Domain Name>\<User ID> -farmservicepassword <Password> -defaultindexlocation "C:\Program Files\Microsoft Office Servers\12.0\Data\Office Server\OSSIndex"

----Extending "site" to internet zone
STSADM -o extendvsinwebfarm -url <New site with Port> -vsname "<Existing site>"

----Configuring Forms Authentication for webapp...
STSADM -o authentication -url <Web app URL with Port> -type forms -membershipprovider FBA_AspNetSqlMembershipProvider -rolemanager FBA_AspNetSqlRoleProvider

Create custom STSADM command

How to create custom STSADM command?
1. Create one class that inherited from ISPStsadmCommand class, And implements below method spcified in the Interface

public string GetHelpMessage(string command)
{
//Your help message.
}

public int Run(string command, StringDictionary keyValues, out string output)
{
//Your custom code using SP object model.
//Set out parameter as out on command prompt.
}

2. Above created dll need to have strong name key.
3. Register the above dll in GAC.
4. Make custom stsadmcommands..xml and put in @ C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\CONFIG.

This file contents the below command.

<Commands>
<command
name="createlist"
class="<ClassName>, <NameSpace>, Version=<No>, Culture=neutral, PublicKeyToken=<Key>"/>
</Commands>

5. Try to run command from command prompt.

Thursday, September 10, 2009

How to Create Job Sceduler in Sharepoint?

How to Create Job Sceduler in Sharepoint?
Create one custom StsadmCommand using ISPStsadmCommand class. And implement Run method, this method will create/Schedule the job. This STSADM calls once while installing product. This will create jobscheduler.(Here scheduler calls every 50 min)

Example:

//This custom STSADM call once while installing product
public class CustomSTSADM : ISPStsadmCommand
{
public int Run(string command, StringDictionary keyValues, out string output)
{
CustomJob.CreateMyJob(URL);
}
}
// SPJobDefinition class
public class CustomJob_Class : SPJobDefinition
{
//Need to override
[SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
public override void Execute(Guid ContentDataBaseID)
{
//TODO: Write what should be done by this job every defined time.
}


//Create JobSchedule for 50 min
Public CustomJob(string Url)
{
SPSite mySite = new SPSite(Url);
SPWebApplication application = mySite.WebApplication;
SPJobDefinitionCollection jobsColl =
application.JobDefinitions;

CustomJob_Class customJob = new CustomJob_Class("CustomJob ",
application);

customJob.Title = " Custom Job ";

SPMinuteSchedule mySchedule = new SPMinuteSchedule();
mySchedule.BeginSecond = 0;
mySchedule.EndSecond = 59;
mySchedule.Interval = 50;
customJob.Schedule = mySchedule;

jobsColl.Add(customJob);
application.Update();
}
}

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.