While using SPSecurity.RunWithElevatedPrivileges in your code, Always remember to create your own Spweb/Spsite objects and to never use an object created outside the RunWithElevatedPrivileges scope.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPWeb web = SPControl.GetContextWeb(Context))
{
//Your Code
}
});
* Advantage of using (SPWeb web ... : Free some Memory!
Thursday, May 15, 2008
Tip : SPSecurity.RunWithElevatedPrivileges
Document Library : Add through RPC Call
Here is the code snippet which uses RPC call to upload document to a SharePoint Document Library }
private void
uploadDocument()
{
Stream io_stream;
MemoryStream stream;
byte[] contents;
string strFileName = string.Empty;string
strPostBody = string.Empty;
bool goAhead = false;
//CURRENT SITE URL
string strCURRENT_SITE_URL = Configuration.getCurrentSiteURL();
//Calculating File Name
strFileName = fileupload.PostedFile.FileName;
if(strFileName.IndexOf("\\")!= -1)
{
strFileName = strFileName.Substring(strFileName.LastIndexOf("\\")+1);
}
strFileName = strFileName.Substring(strFileName.LastIndexOf("\\")+ 1);
//CREATE BOSY STRING FORRPC CALL
strPostBody = GetPostBodyStringWithOutMetaInfo(strCURRENT_SITE_URL,strFileName, string.Empty);
//START UPLOADINGDOCUMENT
stream = new MemoryStream();
io_stream = fileupload.PostedFile.InputStream;
contents = new byte[io_stream.Length];
io_stream.Read(contents, 0, (int)io_stream.Length);
io_stream.Close();
ASCIIEncoding encoding = new ASCIIEncoding();
stream.Write(encoding.GetBytes(strPostBody), 0,strPostBody.Length);
stream.Write(contents,0,contents.Length);strPostBody = SendRequest(strCURRENT_SITE_URL +
"/_vti_bin/_vti_aut/author.dll",
stream.GetBuffer(), stream.Length);
stream.Close();
//END OF UPLOADINGDOCUMENT
//GET DOCUMENT ID USING QUERY FOR ADDING DOCUMENT TO REFERENCE LISTS
SPQuery query = new SPQuery();
int docID;
query.Query = "<Where><Eq><FieldRefName='FileLeafRef' /><Value Type='File'>" + strFileName +"</Value></Eq></Where>";
SPListItemCollection listItemCollection = web.Lists[GreenstoneListNames.GREENSTONE_DOCUMENT_LIBRARY].GetItems(query);
if(listItemCollection.Count> 0)
{
docID = listItemCollection[0].ID;
}
I hope you find it .
Wednesday, May 7, 2008
Customized Theme in MOSS 2007
Windows Sharepoint Server (WSS) and Sharepoint Portal Server (SPS) both ship with several built-in themes, giving you the ability to change the look and feel of a site quite dramatically. Choosing one of these themes is simply a matter of clicking on the “Site Settings” link in the upper navigation and then “Site Theme” under the “look and Feel” header. On the “Site Theme” page you should see a list of available themes on the right. Click on one of these themes and you’ll see a preview on the left of the page. All of the themes available for use on a SharePoint server are stored beneath a single folder named “THEMES“. This folder contains a unique folder for each theme: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\THEMES.
To create a theme, start by creating a new folder with the images and CSS files that make up the theme. Here are the steps to create a new theme called “MOSSTHEME″:
Here is a short procedure of creating a custom site theme named "MossTheme":
1. Copy any theme folder in "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\THEMES" folder and paste with its name replaced with "MossTheme". In this example, copy GRANITE folder.
2. In MossTheme folder, rename GRANITE.INF file to MOSSTHEME.INF in upper case.
3. Open MOSSTHEME.INF file with notepad.
4. Change the value of title under [Info] to MossTheme.
5. Replace every word, Granite, under [titles] with MossTheme.
6. Open "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\SPTHEMES.XML" file with notepad.
7. Add the following lines under
'<' templates '>'
'<'templateid'>'MossTheme '<'/templateid'>'
'<'displayname'>'MossTheme '<'/displayname'>'
'<'description'>'ossTheme '<'/description'>'
'<'thumbnail'>'images/ MossTheme.gif'<'/thumbnail'>'
'<'preview'>'images/ MossTheme.gif'<'/preview'>'
''templates'>'
Notice that preview and thumbnail paths are images/MossTheme.gif. By default, MOSS 2007 and WSS 3.0 will not have such image files.
8. In order to display thumbnail and preview correctly, you will need to capture the screen and save the file in "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\IMAGES" folder with MossTheme.gif name. You can change the .gif file name if you change the thumbnail and preview file names in
9. Do an iisrest for the server to recognize the new theme.
Pretty simple procedure. Now you are ready to test your new theme. In Site Settings, you can now choose MOSSTHEME; however, the theme will not differ from Granite theme. Now, it is time for you to play with theme.css file!
Wednesday, April 30, 2008
Simple XSLT filter for look up column with multiple values
Look up columns drives the relationship hierarchy between lists in SharePoint site. And the most common of all tasks always seems filtering/sorting on certain conditions.
Thursday, April 17, 2008
MOSS Training
Hi !
Today, We feel proud in introducing MOSS 2007 Training modules.
We offer training for both technical staff and end users on all aspects of Microsoft Office SharePoint Server 2007 and SharePoint Portal Server 2003. We also deliver on job training to target specific queries or issues. Please feel free to drop a mail to Hitender or Karun for details
Currently Training is offered only in Delhi/NCR(India) region.
