Showing posts with label SharePoint 2007. Show all posts
Showing posts with label SharePoint 2007. Show all posts

Sunday, January 4, 2015

Allow CAML Query to get items inside Library Folders

Usually a CAML query would query a SharePoint library and get all available items matching the where clause, except the ones within folders of the Library. There is a property which needs to be explicitly set, in order for the query to return all items pertaining to the where clause, including the ones inside folders and nested folders. In the view attribute, the scope needs to be set to Recursive All. A sample CAML query would be:


SPListItemCollection itemCollection = null;
...
...
SPQuery myQuery = new SPQuery();

myQuery.ViewFields = @"<FieldRef Name='UniqueId'/>
                                            <FieldRef Name='ContentType'/>
                                            <FieldRef Name='ID'/><FieldRef Name='FileLeafRef'/>";

                string whereClause = @"<Where>
                                    <Eq>
                                        <FieldRef Name='" + myVariableOne + @"' />
                                            <Value Type='Text'>" + myVariableTwo + @"</Value>
                                    </Eq>
                                  </Where>";

myQuery.Query = whereClause;
myQuery.ViewAttributes += " Scope='RecursiveAll'";


Now use the SPLists GetItems() method to execute the query
Eg: testLibrary.GetItems(myQuery);




Saturday, December 6, 2014

Custom Field Property Display using CAML - SharePoint 2007

SharePoint 2007 Custom field rendering at List Item View is done through the CAML code. In the custom field definition XML file, there is a section where display is defined... and that is within the  <RenderPattern>. Usually you can access the filed properties in the filed through simple CAML code. For an instance:

<RenderPattern Name="DisplayPattern">
  <HTML><![CDATA[</div><br/><br/><div>Name Value:</div><br/>]]></HTML>
  <ScriptQuote>
    <Property Select="Name" HTMLEncode="True" />
  </ScriptQuote>

  <HTML><![CDATA[<div>Custom Property 1 Value</div><br/>]]></HTML>
  <ScriptQuote>  
      <Property Select="MyCustomProperty1" HTMLEncode="True" />
  </ScriptQuote>
  <HTML><![CDATA[<div>Custom Property 2 Value</div><br/>]]></HTML>
  <ScriptQuote>
      <Property Select="MyCustomProperty2" HTMLEncode="True" />
  </ScriptQuote>
  <HTML><![CDATA[<div>Description : </div><br/>]]></HTML>
  <ScriptQuote>
    <Property Select="Description" HTMLEncode="True" />
  </ScriptQuote>
  <HTML><![CDATA[<div>Required : </div><br/>]]></HTML>
  <ScriptQuote>
    <Property Select="Required" HTMLEncode="True" />
  </ScriptQuote>
  <Column HTMLEncode="TRUE"/>

</RenderPattern>


The code would give you the property values of the Description, the required field value and Name value. But.....not the values of the custom properties in your field......

It is possible to get the custom property values and display at DisplayPattern. For this it's required that the property schema's being updated during the field's onAdd() and onUpdate() methods. Solution s to override the two methods.

Then the custom property values become accessible.
A detailed explanation is available at this Link.





Saturday, November 15, 2014

Download file from SharePoint site to the Server Drive for processing

There could be times where one might need to download a file for processing in the server before rendering. May be for a file type conversion prior to rendering or so...During such instances this can be used. The below code block needs to be run within elevated privileges.


web.AllowUnsafeUpdates = true;
SPFile file = web.GetFile(fileUrl);

using (FileStream outStream = new FileStream("Specify the file Download location in server drive"), FileMode.Create))
{
    byte[] obj = (byte[])file.OpenBinary();
    outStream.Write(obj, 0, obj.Length);
}
web.AllowUnsafeUpdates = false;


Side Note:
You can specify the download location in the web.config <AppSettings> section and retrieved via:
ConfigurationManager.AppSettings["AppSettingName"].ToString();


Saturday, November 1, 2014

Creating Content Source and Scope - SharePoint 2007 [Part 1]

Creating a Content Source
In the Central Admin, go to Shared Services.

1) Go to Search Administration page.


2) Select Content Sources


Any web application you create is added into the address list in the default content source which is "Local Office SharePoint Server Sites" 

If you need to have separate search for you web application you can have a separate content source and add a separate search scope for that. This approach can also be used if you need to target your search to retrieve data from target lists.

3) create a new content source, by clicking on the "New Content Source"


Here I have created two new content sources targeting two different search results.

To add web application URL's to the content source you need to go inside the default content source and remove the web application URL first from there, save the content source, and then come back to the newly created content source and include the URL there.



Sunday, April 6, 2014

Execute Server Process from Server Side Code

Sometimes when dealing with certain scenarios, there comes the question, whether a server side process execution could be initiated through server side code. This could be done. In fact this could be done in SharePoint. The code needs to be run withing elevated privileges.



Process proc = new Process();
proc.StartInfo.FileName = string.Concat(ConfigurationManager.AppSettings["Get The File Path"].ToString(), "MYExecutable.exe");
 proc.StartInfo.Arguments = "\"" + ConfigurationManager.AppSettings["argumentOne"].ToString() + file.Name + "\"" + " -o \"" + ConfigurationManager.AppSettings["argumentTwo"].ToString() + myFile + "\"";

proc.StartInfo.UseShellExecute = false;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.RedirectStandardOutput = true;

proc.Start();
proc.WaitForExit();


Sunday, February 16, 2014

Basic PowerShell for SharePoint and the Equivalent STSADM used in Earlier Version

This is a simple list down of basic PowerShell commands used in command line deployments in SharePoint. [SP 2010 and 2013]  &
The equivalent STSADM commands used in SharePoint 2007 ... back in the day ;)


1. Adding a new WSP to farm solution

SP 2010/2013 PowerShell
 Add-SPSolution -LiteralPath "C:\FolderName\Solution.wsp"
SP 2007 
Stsadm
 stsadm -o addsolution -filename "Solution.wsp"
[Assuming command runs from the correct folder location]


2. Deploy WSP 

SP 2010/2013 PowerShell
 Install-SPSolution -Identity "Solution.wsp" -WebApplication "http://WebSiteUrl" -CASPolicies -GACDeployment -Local -Force

AllWebApplications vs WebApplication - All allows the wsp to be deployed in all SP web applocations. WebApplication - allows the wsp to be deployed to a target web app
CASPolicies - Allows Code Access Security Policies to be deployed [optional]
GACDeployment - Allows DLL installation in the global assembly cache [optional]
Force [optional]
Local - Deploys only in the current server [optional]
SP 2007 
Stsadm
stsadm -o deploysolution -name "SolutionName" -url "Site URL" -immediate -allowgacdeployment -allowcaspolicies -force

instead of -url, you can use -allcontenturls 
instead of -immediate, you can use -time "time to deploy"

GACDeployment - Allows DLL installation in the global assembly cache [optional]


3. Activate feature

SP 2010/2013 PowerShell
 Enable-SPFeature –identity "FeatureName" -URL http://WebSiteUrl
SP 2007 
Stsadm
 stsadm -o activatefeature -id feature_ID -url http://WebSiteUrl -force
[Instead of -Id, you can use -filename or -name with appropriate values]



4. De-activate feature

SP 2010/2013 PowerShell
 Disable-SPFeature –identity "FeatureName" -URL http://WebSiteUrl
SP 2007 
Stsadm
stsadm -o deactivatefeature -id feature_ID -url http://WebSiteUrl
[Instead of -Id, you can use -filename or -name with appropriate values]



5. Retract WSP 

SP 2010/2013 PowerShell
Uninstall-SPSolution -Identity "Solution.wsp" -WebApplication http://WebSiteUrl
SP 2007 
Stsadm
stsadm -o retractsolution -name "Solution.wsp" -url http://WebSiteUrl -immediate 
[Instead of -immediate, you can use -time "TimeToRun"]



6. Remove WSP from SharePoint farm

SP 2010/2013 PowerShell
Remove-SPSolution -Identity "Solution.wsp"
SP 2007 
Stsadm
stsadm -o deletesolution -name "Solution.wsp"

Saturday, January 18, 2014

SharePoint Web Parts Maintenance Page

SharePoint web part maintenance pages allows to manage (reset, delete) the web parts embedded into a particular page. It's useful in situations where its required to remove any web parts from a page which has caused a page crash.

For an instance if the page urls is:
http://localhost:1000/SitePages/Home.aspx

you can get the maintenance page by typing in "?contents=1" at the end of the URL string. Below is a sample:

http://localhost:1000/SitePages/Home.aspx?contents=1

This works the same in  SharePoint 2007, 2010 and 2013

Sunday, June 30, 2013

Connecting Server to an existing SharePoint Farm

Once, I had two separate SharePoint 2007 farms having its own server. I needed to change that to one farm with two servers. So I had to remove one farm from one server machine and connect it as a WFE to the existing farm in the other server. The first step was to remove one SharePoint farm.

1) You can use the following command to disconnect the database from SharePoint:

PSCONFIG.EXE -cmd configDB -disconnect








2) Then remove the SharePoint related DB's from SQL Server



3) Run the SharePoint configuration wizard. You get a message as below. Select "Yes".



4) In the configuration wizard, choose connect to existing server farm.



5) Select the database of the server which you need to connect and specify the DB access account to be used. Let the configuration happen.


Now go to the Central Admin. Select Operations. Select Servers in Farm. The new addition to the farm will be listed down.


Monday, May 6, 2013

Installing SharePoint 2007

Back in the day SharePoint 2007 was a hot topic for SharePoint newbies. Seems SP 2007 is still around in use and thought of blogging on key points to note on the installation and configuration.

Installation

Choose the installation type you want. Here I choose Advanced.



Choose the installation server type. I have selected "Complete"

Once the installation is done you will be prompted. Then MOSS will fire up the "SharePoint Products and Technologies Configuration Wizard"

1) System prompts the services that would be restarted before starting the wizard.

2) Server farm option: Creating New vs. Connecting to existing. I'm creating new


3) Specify database settings

4) Specify Central Admin Web App settings

5) Before the wizard starts, the user specified details are displayed

6) Then the wizard runs

7) Once the configuration wizard completes user is prompted of the end result.

8) Then, user is directed to the Central Admin. The "Services on Server" section indicates that services have to be configured



9) Note that you have to start the below services started in the image. Service settings are pretty straight forward.


Creating a new Shared Service Provider

1) Navigate to "Application Management" to create a new SSP. Select the link as shown below:

2) Select "New SSP"

3) In the "New Shared Service Provider" page, specify the web application for SSP and MySite

I have not created any web application yet. Hence I am creating two now. Select the links on the page in order to create new web applications. You will be directed to "Create New Web Application" page. Once it's done system directs you back to the Create SSP page.

3.1) Creating a web application

A web application can be easily created using the following steps. Specify the IIS website and port to be used for the new web application.


Provide the application pool name and the security account to be used.


Provide the database server name, database name & the authentication


Once the two applications are created the SSP can be created. 

4) On completing SSP creation you get a success message


Now in the Shared Services Administration page the SSP is displayed.