I've started to write a piece on What is Code Access Security in SharePoint 2007 and thought I'd put the draft up here to get some feedback -- especially since configuring security has taken prominent place. I'd really appreciate all of your feedback. Thanks! Hament
These days, you can't pick up a blog without reading about the need for the customizing SharePoint as per need of organization. Most of these are done via setting configuration and some time by custom programming too. We as programmer need to think carefully before tweaking the setting for WSS_Minimal and WSS_Medium trust levels. In exceptional cases a third configuration ‘Full’ can also be set. Let me warn you here that this may have serious implications and you may not be able to convince the security group to deploy it in production boxes.
Earlier the security were declared in the web.config file, but that doesn't seem to be the case any more. You will find two pointers to config file of folder localdrive:\program files\common files\microsoft shared\web server extensions\12. The classes are configured for code access level. For example you will find out that SqlClientPermission are not allowed in WSS_Minimal but is allowed in WSS_Medium trust.
Saturday, August 30, 2008
Wednesday, August 27, 2008
Extending OCS
Tuesday, August 26, 2008
STSDEV: Sharepoint Code generator
STSDEV is a proof-of-concept application that demonstrates a simple code generator for create SharePoint 2007 development projects targeting Visual Studio.
http://www.codeplex.com/stsdev
http://www.codeplex.com/stsdev
Monday, August 25, 2008
Find Permission and perform action based on Admin access
Find Permission
SPWeb thisweb = SPControl.GetContextWeb(Context);
isAdmin = thisweb.DoesUserHavePermissions(SPBasePermissions.ManageLists);
if (isAdmin == true)
{
// todo
}
SPWeb thisweb = SPControl.GetContextWeb(Context);
isAdmin = thisweb.DoesUserHavePermissions(SPBasePermissions.ManageLists);
if (isAdmin == true)
{
// todo
}
Sunday, August 24, 2008
Setting URL of link Programatically
SPList list = web.Lists["Links"];
SPListItem newLink = list.Items.Add();
SPFieldUrlValue value = new SPFieldUrlValue();
value.Description = "test";
value.Url = "http://www.microsoft.com/sharepoint";
newLink["URL"] = value;
newLink.Update();
SPListItem newLink = list.Items.Add();
SPFieldUrlValue value = new SPFieldUrlValue();
value.Description = "test";
value.Url = "http://www.microsoft.com/sharepoint";
newLink["URL"] = value;
newLink.Update();
Diaplaying Link field in ItemStyle
< name="LinkList" match="Row[@Style='LinkList']" mode="itemstyle">
< name="DisplayTitle">
< name="OuterTemplate.GetTitle">
< name="Title" select="@URL">
< name="UrlColumnName" select="'URL'">
< /xsl:call-template>
< /xsl:variable>
< name="LinkTarget">
< test="@OpenInNewWindow = 'True'"> _blank< /xsl:if>
< /xsl:variable>
< id="linkitem" class="item">
< class="bullet link-item">
< name="OuterTemplate.CallPresenceStatusIconTemplate">
<>
< name="href">
< select="substring-before($DisplayTitle,', ')">
< /xsl:value-of>
< /xsl:attribute>
< name="title">
< select="@Description">
< /xsl:value-of>
< /xsl:attribute>
< select="substring-after($DisplayTitle,', ')">
< /xsl:value-of>
< /a>
< /div>
< /div>
< /xsl:template>
< name="DisplayTitle">
< name="OuterTemplate.GetTitle">
< name="Title" select="@URL">
< name="UrlColumnName" select="'URL'">
< /xsl:call-template>
< /xsl:variable>
< name="LinkTarget">
< test="@OpenInNewWindow = 'True'"> _blank< /xsl:if>
< /xsl:variable>
< id="linkitem" class="item">
< class="bullet link-item">
< name="OuterTemplate.CallPresenceStatusIconTemplate">
<>
< name="href">
< select="substring-before($DisplayTitle,', ')">
< /xsl:value-of>
< /xsl:attribute>
< name="title">
< select="@Description">
< /xsl:value-of>
< /xsl:attribute>
< select="substring-after($DisplayTitle,', ')">
< /xsl:value-of>
< /a>
< /div>
< /div>
< /xsl:template>
Saturday, August 23, 2008
Surveys Add questions.
Surveys Add questions programatically
SurveysSPListTemplate objTemplate = currentWeb.ListTemplates["mySurvey"];
Guid objGuid = currentWeb.Lists.Add("mycode", "survey", objTemplate);
SPList objSurvey = currentWeb.Lists["mycode"];
//Let’s add questions
StringCollection strQuestions = new StringCollection();
string strQuestion = "What is your favrate colour?";
strQuestions.Add("Red");strQuestions.Add("Blue");
strQuestions.Add("Green");
objSurvey.Fields.Add(strQuestion, SPFieldType.Choice, true, false, strQuestions);
objSurvey.AllowMultiResponses = false;objSurvey.Update();
Friday, August 22, 2008
Preformance Optimization in SharePoint Server 2007
Several areas we have to look here.
1) Delayloading of core .js
You can load it conditionally. Optimizing core.js
2) Browser Cache Settings
You can look here
1) Delayloading of core .js
You can load it conditionally. Optimizing core.js
2) Browser Cache Settings
You can look here
Sample event handler to set field as primary field
Use SPItemEventReceiver to achive same. Query the list, find out item with same title, if present set the cancel property to be true.
see here
see here
Thursday, August 21, 2008
Programmatically retrieve the items in a list based on the current user
Based on the permissions of individual user by using SPQuery. more details here
Programmatically rename a file inside a SharePoint document library
Even if sharepoint file name property is read only you can rename a file by checking it out. more details
Wednesday, August 20, 2008
Find User Name
Find User Name
string loginName = SPControl.GetContextWebContext).CurrentUser.LoginName.ToString();
Tuesday, August 19, 2008
How we can retrieve Discussion Topics (items) from a Discussion List ?
Individual items of the discussion can be found out by finding out the folder. more details
Move file in event handler causes "No item exists" Error
Ishai Sagi discusses a important aspect in moving files ..... He has not SPFile.MoveTo() function since it doesn't support moving to other sites
Ckick here
Ckick here
How To: Customizing alert emails using IAlertNotifyHandler
There are issues with particular field names like ItemName which will be truncated in an alert email at 70 characters. There can also be situations where you want to embed additional content in the email or change the layout and email appearance altogether
Click here
Click here
Monday, August 18, 2008
AllowUnsafeUpdates
if code is processing a POST request then you hve to take care of few things.
Make a call to SPUtility.ValidateFormDigest() before doing anything esle. This will ensure that the post request is validated (that it is not a cross-site scripting attack) and after that you will not have to worry about AllowUnsafeUpdates as this will be marked as true.
more info
Make a call to SPUtility.ValidateFormDigest() before doing anything esle. This will ensure that the post request is validated (that it is not a cross-site scripting attack) and after that you will not have to worry about AllowUnsafeUpdates as this will be marked as true.
more info
here
Sunday, August 17, 2008
How to add a new item to a list
using(SPSite mySite = new SPSite(http://mysite))
{
using(SPWeb myWeb = mySite.OpenWeb())
{
SPList contactsList = myWeb.Lists["Contacts"];
SPListItem mynewItem = contactsList.Items.Add();
mynewItem ["First Name"] = "Hament";
mynewItem ["Last Name"] = "Verma";
mynewItem .Update();
}
}
{
using(SPWeb myWeb = mySite.OpenWeb())
{
SPList contactsList = myWeb.Lists["Contacts"];
SPListItem mynewItem = contactsList.Items.Add();
mynewItem ["First Name"] = "Hament";
mynewItem ["Last Name"] = "Verma";
mynewItem .Update();
}
}
Saturday, August 16, 2008
Faceted Search
New project at codeplex which searches as per category ...
http://www.codeplex.com/FacetedSearch
Some of the advantages listed are
1) Grouping search results by facet
2) Displaying a total number of hits per facet value
3) Refining search results by facet value
http://www.codeplex.com/FacetedSearch
Some of the advantages listed are
1) Grouping search results by facet
2) Displaying a total number of hits per facet value
3) Refining search results by facet value
Hidden User Information List
MOss has every thing in list. Do you know you can see users list too. Log in with appropriate privelages to following link
http://SiteA/_catalogs/users/simple.aspx
you will find the list of all user :)
http://SiteA/_catalogs/users/simple.aspx
you will find the list of all user :)
Custom Site Definition
do you want to include your own site defination with feature enabled or removed?.. here is intrsting areticle from baba
http://mossbaba.blogspot.com/2008/03/custom-site-definition.html
http://mossbaba.blogspot.com/2008/03/custom-site-definition.html
Iterating all lists in the site
using(SPSite mySite = new SPSite(http://server/sites/site))
{
using(SPWeb myWeb = mySite.OpenWeb())
{
string Alllink= "";
foreach(SPList list in myWeb.Lists)
{
string Alllink= ""
+ list.Title + "("+list.Items.Count+")
";
Alllink+= Alllink;
}
}
}
{
using(SPWeb myWeb = mySite.OpenWeb())
{
string Alllink= "";
foreach(SPList list in myWeb.Lists)
{
string Alllink= ""
+ list.Title + "("+list.Items.Count+")
";
Alllink+= Alllink;
}
}
}
Friday, August 15, 2008
Change all items in the list
using(SPSite mySite = new SPSite(http://mysite))
{
using(SPWeb myWeb = mySite.OpenWeb())
{
SPList contactsList = myWeb.Lists["Contacts"];
foreach(SPListItem existingItem in contactsList.Items)
{
existingItem["E-mail Address"] = "test"
newItem.Update();
}
}
}
{
using(SPWeb myWeb = mySite.OpenWeb())
{
SPList contactsList = myWeb.Lists["Contacts"];
foreach(SPListItem existingItem in contactsList.Items)
{
existingItem["E-mail Address"] = "test"
newItem.Update();
}
}
}
how to get item's properties
using(SPSite mySite = new SPSite("mysite"))
{
using(SPWeb myWeb = mySite.OpenWeb())
{
SPList mycontactsList = myWeb.Lists["MyContacts"];
foreach (SPListItem contact in mycontactsList .Items)
{
string contactLastName = contact["Last Name"].ToString();
}
}
}
{
using(SPWeb myWeb = mySite.OpenWeb())
{
SPList mycontactsList = myWeb.Lists["MyContacts"];
foreach (SPListItem contact in mycontactsList .Items)
{
string contactLastName = contact["Last Name"].ToString();
}
}
}
how to get the object for a list whose name is known
using(SPSite mySite = new SPSite("mysite"))
{
using(SPWeb myWeb = mySite.OpenWeb())
{ SPList contactsList = myWeb.Lists["nameoflist"];
}
}
{
using(SPWeb myWeb = mySite.OpenWeb())
{ SPList contactsList = myWeb.Lists["nameoflist"];
}
}
Geeting reference to a site
This is quite straight forward
using(SPSite mySite = new SPSite(http://mysite))
{
using(SPWeb myWeb = mySite.OpenWeb())
{
}
}
using(SPSite mySite = new SPSite(http://mysite))
{
using(SPWeb myWeb = mySite.OpenWeb())
{
}
}
Wednesday, August 13, 2008
SharePoint 2007 Maximum Limitations
Intresting blog by harsh on sharepoint limitation.
Site Name 128 characters
Site URL 255 characters
Display name 128 characters
Connection string 384 characters
Email address 128 characters
Version numbers 064 characters
Virtual Server Friendly Name 064 characters
SQL Database Name 123 characters
More here
Site Name 128 characters
Site URL 255 characters
Display name 128 characters
Connection string 384 characters
Email address 128 characters
Version numbers 064 characters
Virtual Server Friendly Name 064 characters
SQL Database Name 123 characters
More here
Auto refresh sharepoint page...
You can add content editor web part and add the javascript to refresh after x seconds.
See comments to find out how to overcome the message "need to post data"
http://drewmace.blogspot.com/2008/02/auto-refresh-sharepoint-page.html
See comments to find out how to overcome the message "need to post data"
http://drewmace.blogspot.com/2008/02/auto-refresh-sharepoint-page.html
Monday, August 11, 2008
Programatically creating 1000 of folder with unique permission
this is far more simple and straightfoward. we can use web service to do that. more details
Permission for SPSecurityTrimmedControl
you can use SPSecurityTrimmedControl to customize as per the security.
'<' SharePoint:SPSecurityTrimmedControl PermissionsString="AddAndCustomizePages, ManageLists" runat="server"'>'
'<'/SharePoint:SPSecurityTrimmedControl'>'
The content within the control will be shown based on users access level.
The permission are like..
AddListItems
EditListItems
DeleteListItems
ViewListItems
ApproveItems
OpenItems
Zac Smith has listed all of them here
'<' SharePoint:SPSecurityTrimmedControl PermissionsString="AddAndCustomizePages, ManageLists" runat="server"'>'
'<'/SharePoint:SPSecurityTrimmedControl'>'
The content within the control will be shown based on users access level.
The permission are like..
AddListItems
EditListItems
DeleteListItems
ViewListItems
ApproveItems
OpenItems
Zac Smith has listed all of them here
Friday, August 8, 2008
Updating UserProfile Property of type ChoiceList
before updating the “ChoiceList” set the “MaximumShown” property to a higher value (depends on how many items you are adding)...
PropertyCollection props = m_mngr.Properties;
Property location = props.GetPropertyByName("CountryList");
Location.MaximumShown = Location.MaximumShown +1;
more
PropertyCollection props = m_mngr.Properties;
Property location = props.GetPropertyByName("CountryList");
Location.MaximumShown = Location.MaximumShown +1;
more
How to set SPFolder.WelcomePage property?
SPSite site = new SPSite("http://server:100/sites/InternetSite/");
SPWeb web = site.OpenWeb();
SPFolder folder = web.RootFolder;
folder.WelcomePage = "TestWiki/Hello1.aspx";
this will work more
SPWeb web = site.OpenWeb();
SPFolder folder = web.RootFolder;
folder.WelcomePage = "TestWiki/Hello1.aspx";
this will work more
How to customize your SharePoint site?
All teplates are in 12\TEMPLATE\SiteTemplates. New templates can be developed inside 12\TEMPLATE\SiteTemplates. For more details click here
Updates are currently disallowed on GET requests. while creating a WSS site
you may need to impersonate the user and register hidden field
SPGlobalAdmin globalAdmin = new SPGlobalAdmin();
Context.Items[SPGlobalAdmin.RequestFromAdminPort] = true;
Page.RegisterHiddenField("__REQUESTDIGEST", globalAdmin.AdminFormDigest);
more
SPGlobalAdmin globalAdmin = new SPGlobalAdmin();
Context.Items[SPGlobalAdmin.RequestFromAdminPort] = true;
Page.RegisterHiddenField("__REQUESTDIGEST", globalAdmin.AdminFormDigest);
more
Wednesday, August 6, 2008
Site Defination viewer
You can see Site Definition Configurations, All Site Features ,manifests files , receiver classes, stapled features via .NET2 application more info here.
http://blogs.msdn.com/maximeb/archive/2008/02/16/site-definition-viewer-a-windows-net-2-0-tool-to-read-site-definition-and-features-configurations-version-0-1.aspx
http://blogs.msdn.com/maximeb/archive/2008/02/16/site-definition-viewer-a-windows-net-2-0-tool-to-read-site-definition-and-features-configurations-version-0-1.aspx
26 feb 08
Tuesday, August 5, 2008
Some cool functionalities of UserGroup.asmx webservice
The Users and Groups Web service provides methods for working with users and groups in Windows SharePoint Services. more details
How we can work with output cache programmatically ?
not only cache policy can be created programatically, you can configure it too. more details here
Monday, August 4, 2008
Make the "Overwrite existing file" check box to be unselected by default in MOSS 2007
while uploading doucment if you want the ovewirte option to be unchecked by defalut ... make changes in xml of TEMPLATE\1033\SPSTOC\LISTS\DOCLIB IIS reset is needed to reflect the changes.
more
more
"Invalid data has been used to update the list item. The field you are trying to update may be read only" - when updating BEGIN - END fields in an eve
if either Begin or end is missing you will get the error
more
more
https:// in which case 7 needs to be 8 */
string goodUrl = Page.Request.Url.ToString();
int startCount = 7;
/* this is to rip-off http:// unless you are using https:// in which case 7 needs to be 8 */
int index = goodUrl.IndexOf("/",startCount,goodUrl.Length-(startCount+1));
goodUrl = goodUrl.Substring(0,index);
more
int startCount = 7;
/* this is to rip-off http:// unless you are using https:// in which case 7 needs to be 8 */
int index = goodUrl.IndexOf("/",startCount,goodUrl.Length-(startCount+1));
goodUrl = goodUrl.Substring(0,index);
more
Changing Quota Template Names in SharePoint V2
Quota template helps you to manage the grown in site within Admin control
SPGlobalAdmin globalAdmin = new SPGlobalAdmin();
SPGlobalConfig globalConfig = globalAdmin.Config;
SPQuotaTemplateCollection templates = globalConfig.QuotaTemplates;
foreach(SPQuotaTemplate template in templates)
{
if(template.Name == “Personal Site”)
{
template.Name = “Modified Personal Site”;
template.Add(template);
Console.WriteLine(“Quota Template name changed!!”);
break;
}
}
more
SPGlobalAdmin globalAdmin = new SPGlobalAdmin();
SPGlobalConfig globalConfig = globalAdmin.Config;
SPQuotaTemplateCollection templates = globalConfig.QuotaTemplates;
foreach(SPQuotaTemplate template in templates)
{
if(template.Name == “Personal Site”)
{
template.Name = “Modified Personal Site”;
template.Add(template);
Console.WriteLine(“Quota Template name changed!!”);
break;
}
}
more
Getting Event Handlers developed in VS.NET 2005 to work with SharePoint V2
upgrade the IIS to use Asp.Net 2
more
more
FullTextSqlQuery with QueryText length greater than 4096 characters throws ArgumentOutOfRange exception.
this is limitation of moss more
Add/Update "sealed" properties in SharePoint lists
resolve with SPSecurity.RunWithElevatedPrivileges
more details here
more details here
Programming navigation in WSS 3.0
SPNavigationNodeCollection nodes = web.Navigation.TopNavigationBar;
SPNavigationNode newNode1 = new SPNavigationNode("MS TechNet", "http://technet.microsoft.com", true);
SPNavigationNode newNode2 = new SPNavigationNode("SharePoint SDK Online", "http://msdn.microsoft.com/sharepoint", true);
more details
SPNavigationNode newNode1 = new SPNavigationNode("MS TechNet", "http://technet.microsoft.com", true);
SPNavigationNode newNode2 = new SPNavigationNode("SharePoint SDK Online", "http://msdn.microsoft.com/sharepoint", true);
more details
The security validation for this page is invalid" error when updating objects through SharePoint object model
Project to customize the small search control in SharePoint 2007
This control is actually available through a feature called "OSearchBasicFeature" located under 12\TEMPLATE\FEATURES. In the feature elements file (in this feature it's called "SearchArea.xml"), you can see the following
more
more
What permissions are behind the permission levels (roles) in SharePoint
find out what SPBasePermissions are assigned behind permission level in SharePoint using SharePoint OM code
more details
more details
FBA and User Display Names
try
{
SPUser user = web.AllUsers[loginName];
user.Name = displayName;
user.Email = email;
user.Update();
Page.Response.Redirect(web.Site.Url.ToString());
}
more details
{
SPUser user = web.AllUsers[loginName];
user.Name = displayName;
user.Email = email;
user.Update();
Page.Response.Redirect(web.Site.Url.ToString());
}
more details
Organization Hierarchy a Mess?
All that the customer had to do was to login to open their http:///person.aspx page using SPD. Find the control and delete it
more details
more details
Using Post Caching Substitution in SharePoint 2007 Web Parts
there are scenarios where you might want to implement output caching on your site/page, but have some controls (Web Parts, User Control) excluded from caching so that they dynamically have their content updated on every request.
more details
more details
How to download files from a SharePoint document library remotely via Lists.asmx webservice
Lists.asmx web service which is available in the /_Vti_Bin/ location of the site and we can use GetListItems() method for returning the information about document library items as XML.
more detail
more detail
Make BDC work with FBA
Making BDC (Business Data Catalog) work with FBA (Form Based Authentication) requires a bit of work. to resolve error more
Sunday, August 3, 2008
A way of hiding ListViewWebParts in all pages of SharePoint site in a single shot
create a user control and implemented the logic in the OnLoad() event to hide the webparts. Register that control in a custom master page and applied it to the SharePoint site and it worked well.
more detail
more detail
create publishing pages in portal sites programmatically and add it into a specific folders inside the Pages library
executing code with elevated privileges will help whenever we create the publishing pages from a sharepoint portal site for an another portal site.If we create the publishing page within a site collection then this code will execute fine without elevated privileges. more
How to debug inline code of custom layout pages
change in web.config file by making the debug="true" more detail
How to show task creator's & modifier's name instead of "System Account" in the Task Library
Create an event handler – ItemAdded & ItemUpdated, which will capture the event whenever a new task Item added to the Task List and whenever we modify that task by approving/rejecting the workflow task. more
How to enable users to download infected files when a download scan that is performed by using anti-virus software is disabled?
yopu need to set property AllowQuarantinedFileDownload to true more
Creating a read-only field with default value in a SharePoint list
if you want to create a read-only column with default value and with condition that nobody can edit it, then you can implement it by using the FieldAdded event more
publishing portal pages : "Value does not fall within the expected range"
Happens mostly when page is corrupted or have incorrect top level site URL. more
SPSecurity.RunWithElevatedPrivileges - an important point while using it in web context
Do not forget to create a new instance of SPSite and SPWeb inside SPSecurity.RunWithElevatedPrivileges more
Rename a File in a SharePoint document library through object model
we have to first check-out the file and after renaming the file we have to check-in it more
How to take out the dlls from GAC ?
Some time you need to take a dll out of GAC programatically. you need to dive deep inside GAC_MSIL more
work around for customization of core.js
use a custom master page to that particular site collection and override the core.js file instead of using the original one. more
implement a custom mechanism to delete the audit entries in your SharePoint site
There was no way of deleting the audit log entries in SharePoint till the release of infrastructure update more
Problem with PeopleEditor
PeopleEditor control will display the CommaSeparatedAcccounts value only if we provide the values to that property before adding it to the control array. That means we have to provide the values inside the CreateChildControl method.
more
more
Update email addresses of all users
if the domain name has chnaged and you want to update email of all user
more
Retrieving the metadata information of a current approved version of a list item
try accessing the version with the index of of the version number and the column name. more
A requirement that you want to add some webparts while creating a new site
We don’t have any event handlers for site created or web created to capture that event. But, we have a wonderful feature which is nothing but Feature Stapling . more
Issue with the WebPartManager class while adding webparts dynamically to a specific webpart zone
AddWebPart () method of WebPartManager class, it will add the webpart to a specified webpart zone, but if we do page refresh or a post back, will keep the newly added webpart some other webpart zone in the page. Bizarre....
more
more
How we can create documents inside a document library based upon the content type’s document template?
SPFile oFile = projectDocumentLibrary.RootFolder.Files.Add("TestDoc1.doc", oWeb.GetFile(oContentType .DocumentTemplateUrl).OpenBinary(), true);
more
more
Friday, August 1, 2008
Attempted to read or write protected memory
Have to came accross error like this...
Event Id: 6398
Event Source: Windows SharePoint Services 3
The Message text contains: "Microsoft.Office.Server.Administration.
ApplicationServerAdministrationServiceJob" and "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
6482, 7076
Microsoft has released fix for this
Event Id: 6398
Event Source: Windows SharePoint Services 3
The Message text contains: "Microsoft.Office.Server.Administration.
ApplicationServerAdministrationServiceJob" and "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
6482, 7076
Microsoft has released fix for this
Subscribe to:
Posts (Atom)