Code below will list down a site's owners or users with full control
//first try the code below, should work most of the time
//unless users/admins mess up with the default groups
try
{
SPGroup myOwnerGroup = myWeb.AssociatedOwnerGroup;
foreach (SPUser myOwner in myOwnerGroup.Users)
{
//do what needs to be done here
}
}
catch (Exception ex)
{
//just ignore & proceed with the fall back mechanism to get the owners
}
//if the code above didn't return any values then the code below is the fall back mechanism
SPSite mySite = new SPSite(<website url>);
SPWeb myWeb = mySite.OpenWeb();
try
{
foreach (SPUser myWebUser in myWeb.AllUsers)
{
if (myWeb.DoesUserHavePermissions(myWebUser.LoginName, SPBasePermissions.ManagePermissions))
{
//do what needs to be done here
}
}
}
catch (Exception ex)
{
//error processing here
}
Showing posts with label SharePoint 2007. Show all posts
Showing posts with label SharePoint 2007. Show all posts
Friday, August 12, 2011
Wednesday, July 20, 2011
Customizing SharePoint 2007 "Access Denied" Page
In SharePoint 2010, we can run the powershell command below to "tell" SharePoint that we have our own "Custom Access Denied" page & which web applications should use that custom page.
Set-SPCustomLayoutsPage -Identity <None | AccessDenied | Confirmation | Error | Login | RequestAccess | Signout
| WebDeleted> -RelativePath <String> -WebApplication <SPWebApplicationPipeBind>
[-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-WhatIf [<SwitchParameter>]]
However, we don't have the same feature in SharePoint 2007. Below is a workaround to achieve just that. Explanation follows.
1. First make a backup copy of out of box version of the AccessDenied.aspx file. Keep it safe somewhere.
2. Open the Accessdenied.aspx file in your favourite editor (Notepad? Visual Studio?)
3. Insert the code below in the file between the last register statement line and content place holder code
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string strIncoming = Page.Request.Url.AbsoluteUri.ToLower();
string strTargetURL = "";
string strSource = Request.QueryString["Source"];
string strType = Request.QueryString["type"];
string strQuery = "";
///Check if its customized web apps
if (IsCADeniedWebApp(strIncoming))
{
//check if user is trying to sign in as another user
if (!strIncoming.Contains("loginasanotheruser"))
{
strQuery = "Source=" + strSource + "&Type=" + strType;
strTargetURL = "/_layouts/<your custom folder>/<your custom page>" + strQuery;
SPUtility.Redirect(strTargetURL, SPRedirectFlags.Default, HttpContext.Current);
}
}
}
private bool IsCADeniedWebApp(string strURL)
{
try
{
string strWebApp = "";
string[] arrWebApps = File.ReadAllLines("C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\12\\TEMPLATE\\LAYOUTS\\<your custom folder>\\CustomisedWebApps.txt");
int intNumberOfWebApps = arrWebApps.Length;
for (int i = 0; i < intNumberOfWebApps; i++)
{
if (arrWebApps[i] != null)
{
strWebApp = arrWebApps[i].Trim();
if (strWebApp != "")
{
if (strURL.Contains(strWebApp))
return true;
}
}
}
return false;
}
catch (Exception ex)
{
return false;
}
}
</script>
The code makes use of a text file which contains the list of web apps that will use the customized access denied page.
Basically, the code above will check for 2 conditions.
i) if the URL that user accessing belongs to a web apps that uses customized access denied page. If not, just ignore it.
ii) if user is trying to login as another user. For some reason, MS is re-using the AccessDenied.aspx to handle "signing in as another user".
If, the URL belongs to the web apps that uses customized access denied page and user is not trying to sign in as another user, the code will redirect the user to another page. this is where you need to add your custom code.In my case, i will display the list of users with full control to the site or resource.
Set-SPCustomLayoutsPage -Identity <None | AccessDenied | Confirmation | Error | Login | RequestAccess | Signout
| WebDeleted> -RelativePath <String> -WebApplication <SPWebApplicationPipeBind>
[-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-WhatIf [<SwitchParameter>]]
However, we don't have the same feature in SharePoint 2007. Below is a workaround to achieve just that. Explanation follows.
1. First make a backup copy of out of box version of the AccessDenied.aspx file. Keep it safe somewhere.
2. Open the Accessdenied.aspx file in your favourite editor (Notepad? Visual Studio?)
3. Insert the code below in the file between the last register statement line and content place holder code
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string strIncoming = Page.Request.Url.AbsoluteUri.ToLower();
string strTargetURL = "";
string strSource = Request.QueryString["Source"];
string strType = Request.QueryString["type"];
string strQuery = "";
///Check if its customized web apps
if (IsCADeniedWebApp(strIncoming))
{
//check if user is trying to sign in as another user
if (!strIncoming.Contains("loginasanotheruser"))
{
strQuery = "Source=" + strSource + "&Type=" + strType;
strTargetURL = "/_layouts/<your custom folder>/<your custom page>" + strQuery;
SPUtility.Redirect(strTargetURL, SPRedirectFlags.Default, HttpContext.Current);
}
}
}
private bool IsCADeniedWebApp(string strURL)
{
try
{
string strWebApp = "";
string[] arrWebApps = File.ReadAllLines("C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\12\\TEMPLATE\\LAYOUTS\\<your custom folder>\\CustomisedWebApps.txt");
int intNumberOfWebApps = arrWebApps.Length;
for (int i = 0; i < intNumberOfWebApps; i++)
{
if (arrWebApps[i] != null)
{
strWebApp = arrWebApps[i].Trim();
if (strWebApp != "")
{
if (strURL.Contains(strWebApp))
return true;
}
}
}
return false;
}
catch (Exception ex)
{
return false;
}
}
</script>
The code makes use of a text file which contains the list of web apps that will use the customized access denied page.
Basically, the code above will check for 2 conditions.
i) if the URL that user accessing belongs to a web apps that uses customized access denied page. If not, just ignore it.
ii) if user is trying to login as another user. For some reason, MS is re-using the AccessDenied.aspx to handle "signing in as another user".
If, the URL belongs to the web apps that uses customized access denied page and user is not trying to sign in as another user, the code will redirect the user to another page. this is where you need to add your custom code.In my case, i will display the list of users with full control to the site or resource.
Wednesday, March 30, 2011
Setting up Adobe PDF iFilter 9 for SharePoint 2007
I am posting this for my own future reference :-p and other newbies like me :-).
I downloaded the Adobe Pdf iFilter from here. And then followed the instructions.
But I got error (below)
Crawled (The filtering process could not process this item.This might be because you do not have the latest file filter for this type of item. Install the corresponding filter and retry your crawl. )
So when I googled around, I was pointed to many forums and blogs on how to overcome the error. I find this article very informative especially when it mentioned about checking the second registry key.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\12.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf]
But after I made the changes, I was still getting the error. After troubleshooting for a while. I found out that I made a silly mistake !! I forgot about the curly brackets. I changed the registry values for the two keys above to {E8978DA6-047F-4E3D-9C78-CDBE46041603} and it works perfectly now.
I downloaded the Adobe Pdf iFilter from here. And then followed the instructions.
But I got error (below)
Crawled (The filtering process could not process this item.This might be because you do not have the latest file filter for this type of item. Install the corresponding filter and retry your crawl. )
So when I googled around, I was pointed to many forums and blogs on how to overcome the error. I find this article very informative especially when it mentioned about checking the second registry key.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\12.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf]
But after I made the changes, I was still getting the error. After troubleshooting for a while. I found out that I made a silly mistake !! I forgot about the curly brackets. I changed the registry values for the two keys above to {E8978DA6-047F-4E3D-9C78-CDBE46041603} and it works perfectly now.
Friday, November 26, 2010
MOSS 2007 upgrade to SharePoint 2010
Requirements, requirements & REQUIREMENTS - gathering, understanding, refinement, gathering, understanding, refinement, gathering ....
We need to understand the business and customers'/users' requirements first. The requirements can be broken into existing SharePoint 2007 usage scenarios and new usage scenarios. Since SharePoint 2010 enables lots of cool new features, we should educate our users on the new features and understand which ones appeals to them.
Once we understand the requirements, we can then map them into the services that is needed to fulfill those requirements. It is good to have some knowledge on the those services especially in terms of hardware requirements to run them properly. We need to truly understand what services are needed and how intensive they will be used. If what we have collected from users cannot answer these two important questions, then we need to go back to users. This is a very important activity as it will help us to get the right hardware to build our SharePoint 2010 environment.
We need to understand the business and customers'/users' requirements first. The requirements can be broken into existing SharePoint 2007 usage scenarios and new usage scenarios. Since SharePoint 2010 enables lots of cool new features, we should educate our users on the new features and understand which ones appeals to them.
Once we understand the requirements, we can then map them into the services that is needed to fulfill those requirements. It is good to have some knowledge on the those services especially in terms of hardware requirements to run them properly. We need to truly understand what services are needed and how intensive they will be used. If what we have collected from users cannot answer these two important questions, then we need to go back to users. This is a very important activity as it will help us to get the right hardware to build our SharePoint 2010 environment.
Wednesday, November 24, 2010
Perfmon Counters to Monitor SharePoint Environment's Servers
List of perfmon counters that I gathered for MOSS 2007. However, I believe it is applicable for SharePoint 2010 as well.
Tuesday, August 17, 2010
Visual Basic script to manipulate an element in DOCICON.XML file
'Purpose: To add/update/remove the element
'into DOCICON.XML file make the installation/uninstallation of Foxit PDF iFilter complete
blnRevert = false
strAction = ""
'*** Arguments Section ***
If wscript.arguments.count = 1 Then
if lcase(wscript.arguments(0)) = "-update" OR lcase(wscript.arguments(0)) = "/update" Then
strAction = "update"
elseif lcase(wscript.arguments(0)) = "-remove" OR lcase(wscript.arguments(0)) = "/remove" Then
strAction = "remove"
else
call OutPutUsage
wscript.quit
end if
else
call OutPutUsage
wscript.quit
end if
strFileName = "C:\Program Files\Common Files\Microsoft Shared\Web server extensions\12\Template\Xml\DOCICON.XML"
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
blnFileExists = objXMLDoc.load(strFileName)
if blnFileExists = 0 then
OutPut strFileName + " file not found."
OutPut "Script will terminate"
wscript.quit
end if
Dim objCurrNode, objNewNode, objNewText, xmlTmpNode
Set objCurrNode = objxmlDoc.selectSingleNode("/DocIcons/ByExtension")
Dim i, blnElementExist
i = 0
blnElementExist = 0
for each xmlTmpNode in objCurrNode.ChildNodes
' OutPut xmlTmpNode.xml
strAttValue = xmlTmpNode.getAttribute("Key")
if lcase(strAttValue) = "pdf" then
blnElementExist = 1
exit for
else i = i + 1
end if
next
if strAction = "remove" then
if blnElementExist = 0 then
OutPut "Key Not found. No changes will be made."
else
objCurrNode.removeChild objCurrNode.ChildNodes(i)
objXMLDoc.save(strFileName)
OutPut "Key=PDF has been removed."
end if
else
if blnElementExist = 1 then
strAttValue = ""
strAttValue = xmlTmpNode.getAttribute("Value")
if lcase(strAttValue) "icpdf.gif" then
Set objNewNode = objxmlDoc.createNode(1,"Mapping","")
objNewNode.setAttribute "Key","pdf"
objNewNode.setAttribute "Value","icpdf.gif"
objCurrNode.replaceChild objNewNode, objCurrNode.ChildNodes(i)
Set objCurrNode = objCurrNode.lastChild
objXMLDoc.save(strFileName)
OutPut "Value for Key=pdf updated to icpdf.gif"
else OutPut "Key with correct value already exists. No changes will be made"
end if
else
Set objNewNode = objxmlDoc.createNode(1,"Mapping","")
objNewNode.setAttribute "Key","pdf"
objNewNode.setAttribute "Value","icpdf.gif"
objCurrNode.appendChild(objNewNode)
Set objCurrNode = objCurrNode.lastChild
objXMLDoc.save(strFileName)
OutPut "New element created: "
end if
end if
'OutPut objXMLDoc.xml
SUB OutPutUsage
OutPut ""
OutPut " " & wscript.scriptname & " is used to update or remove into DOCICON.XML"
OutPut ""
OutPut " Usage:"
OutPut ""
Output " " & wscript.scriptname & " [-update | -remove]"
OutPut ""
END SUB
SUB OutPut(strStringToOutPut)
wscript.echo strStringToOutPut
END SUB
So, in your bat file you do this:-
cscript.exe //nologo MOSS_DOCICON_Setting.vbs /update
or
cscript.exe //nologo MOSS_DOCICON_Setting.vbs /remove
'into DOCICON.XML file make the installation/uninstallation of Foxit PDF iFilter complete
blnRevert = false
strAction = ""
'*** Arguments Section ***
If wscript.arguments.count = 1 Then
if lcase(wscript.arguments(0)) = "-update" OR lcase(wscript.arguments(0)) = "/update" Then
strAction = "update"
elseif lcase(wscript.arguments(0)) = "-remove" OR lcase(wscript.arguments(0)) = "/remove" Then
strAction = "remove"
else
call OutPutUsage
wscript.quit
end if
else
call OutPutUsage
wscript.quit
end if
strFileName = "C:\Program Files\Common Files\Microsoft Shared\Web server extensions\12\Template\Xml\DOCICON.XML"
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
blnFileExists = objXMLDoc.load(strFileName)
if blnFileExists = 0 then
OutPut strFileName + " file not found."
OutPut "Script will terminate"
wscript.quit
end if
Dim objCurrNode, objNewNode, objNewText, xmlTmpNode
Set objCurrNode = objxmlDoc.selectSingleNode("/DocIcons/ByExtension")
Dim i, blnElementExist
i = 0
blnElementExist = 0
for each xmlTmpNode in objCurrNode.ChildNodes
' OutPut xmlTmpNode.xml
strAttValue = xmlTmpNode.getAttribute("Key")
if lcase(strAttValue) = "pdf" then
blnElementExist = 1
exit for
else i = i + 1
end if
next
if strAction = "remove" then
if blnElementExist = 0 then
OutPut "Key Not found. No changes will be made."
else
objCurrNode.removeChild objCurrNode.ChildNodes(i)
objXMLDoc.save(strFileName)
OutPut "Key=PDF has been removed."
end if
else
if blnElementExist = 1 then
strAttValue = ""
strAttValue = xmlTmpNode.getAttribute("Value")
if lcase(strAttValue) "icpdf.gif" then
Set objNewNode = objxmlDoc.createNode(1,"Mapping","")
objNewNode.setAttribute "Key","pdf"
objNewNode.setAttribute "Value","icpdf.gif"
objCurrNode.replaceChild objNewNode, objCurrNode.ChildNodes(i)
Set objCurrNode = objCurrNode.lastChild
objXMLDoc.save(strFileName)
OutPut "Value for Key=pdf updated to icpdf.gif"
else OutPut "Key with correct value already exists. No changes will be made"
end if
else
Set objNewNode = objxmlDoc.createNode(1,"Mapping","")
objNewNode.setAttribute "Key","pdf"
objNewNode.setAttribute "Value","icpdf.gif"
objCurrNode.appendChild(objNewNode)
Set objCurrNode = objCurrNode.lastChild
objXMLDoc.save(strFileName)
OutPut "New element created: "
end if
end if
'OutPut objXMLDoc.xml
SUB OutPutUsage
OutPut ""
OutPut " " & wscript.scriptname & " is used to update or remove into DOCICON.XML"
OutPut ""
OutPut " Usage:"
OutPut ""
Output " " & wscript.scriptname & " [-update | -remove]"
OutPut ""
END SUB
SUB OutPut(strStringToOutPut)
wscript.echo strStringToOutPut
END SUB
So, in your bat file you do this:-
cscript.exe //nologo MOSS_DOCICON_Setting.vbs /update
or
cscript.exe //nologo MOSS_DOCICON_Setting.vbs /remove
Friday, August 6, 2010
Visual basic script to check the status of a MOSS 2007 solution
A simple VB script that I wrote about 2 years back to automate solution deployment.
dim strSolutions , intReturnValue
strSolutions = "There are no items matching the criteria specified."
intReturnValue = 2 'solution not installed
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec("C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\stsadm -o enumsolutions")
strSolutions = objScriptExec.StdOut.ReadAll
strSolutions = Trim(strSolutions)
pos=InStr(1,strSolutions,"There are no items",1)
if pos = 0 then
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.loadXML(strSolutions)
Dim objCurrNode, strDeployStatus
Set objCurrNode = objxmlDoc.selectSingleNode("/Solutions")
for each xmlTmpNode in objCurrNode.ChildNodes
strAttValue = xmlTmpNode.getAttribute("Name")
if lcase(strAttValue) = "" then
set ElementsList= xmlTmpNode.getElementsByTagName("Deployed")
for each Elem In ElementsList
strDeployStatus = Elem.firstChild.nodeValue
if LCase(Trim(strDeployStatus)) = "true" then
intReturnValue = 4 'solution installed & deployed
else
intReturnValue = 3 'solution installed BUT NOT deployed
end if
next
exit for
end if
next
end if
Wscript.Quit(intReturnValue)
dim strSolutions , intReturnValue
strSolutions = "There are no items matching the criteria specified."
intReturnValue = 2 'solution not installed
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec("C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\stsadm -o enumsolutions")
strSolutions = objScriptExec.StdOut.ReadAll
strSolutions = Trim(strSolutions)
pos=InStr(1,strSolutions,"There are no items",1)
if pos = 0 then
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.loadXML(strSolutions)
Dim objCurrNode, strDeployStatus
Set objCurrNode = objxmlDoc.selectSingleNode("/Solutions")
for each xmlTmpNode in objCurrNode.ChildNodes
strAttValue = xmlTmpNode.getAttribute("Name")
if lcase(strAttValue) = "" then
set ElementsList= xmlTmpNode.getElementsByTagName("Deployed")
for each Elem In ElementsList
strDeployStatus = Elem.firstChild.nodeValue
if LCase(Trim(strDeployStatus)) = "true" then
intReturnValue = 4 'solution installed & deployed
else
intReturnValue = 3 'solution installed BUT NOT deployed
end if
next
exit for
end if
next
end if
Wscript.Quit(intReturnValue)
Wednesday, August 4, 2010
Multilingual Support in SharePoint
I was searching for articles to learn how to enable multilingual support in SharePoint and would recommend these two articles (links below) for anyone else interested to do the same.
Basically there are 2 ways to do it depending on what you want to achieve.
First one is to use a feature called Variation. It looks quite straight forward to implement but there is few limitations to it including that it is limited to publishing site template. Read more here: MOSS_multilingual_variation.
The second way is by a feature called Localization which leverages on the resource files. Read more here: Localization of SharePoint Project
Basically there are 2 ways to do it depending on what you want to achieve.
First one is to use a feature called Variation. It looks quite straight forward to implement but there is few limitations to it including that it is limited to publishing site template. Read more here: MOSS_multilingual_variation.
The second way is by a feature called Localization which leverages on the resource files. Read more here: Localization of SharePoint Project
Friday, July 9, 2010
SharePoint 2007 Search Issues Troubleshooting
Are you having any search related issues? Try the troubleshooting steps below and see if it helps you to identify the cause.
1. Check if search services are running.
If not --> restart it by going to Central Admin -> Operations -> Services on Server
2. Check if content db is assigned to a index server.
If not --> Application Management > Content Databases > Select the content database
3. If search is running and content db is assigned correctly but you can see any results, then check if indexing/crawling is still running. if yes, you have to wait till it completed before doing your search again.
4. If still cannot search, then try running FULL index again. You may need to delete existing index files and run full index again either by
i) using UI - SSP Search config
ii) using stsadm commands
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm –o spsearch –action fullcrawlstop
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm –o spsearch –action fullcrawlstart
5. You should also check if the file file ext is included in files to be indexed (in SSP Search config). Note that not all files are indexable or included in indexing.
6. Additionally, check the search visibility under Site Actions > Site Settings > Search visibility to check whether that particular site and its contents are included in crawling
7. It can be a crawler access issue. If yes, Reset the rights of the crawler account to the content database thru SQL Enterprise Mgr/Mmgt Studio and/or check the check web application policy whereby the crawl account must have "Full Read" access.
1. Check if search services are running.
If not --> restart it by going to Central Admin -> Operations -> Services on Server
2. Check if content db is assigned to a index server.
If not --> Application Management > Content Databases > Select the content database
3. If search is running and content db is assigned correctly but you can see any results, then check if indexing/crawling is still running. if yes, you have to wait till it completed before doing your search again.
4. If still cannot search, then try running FULL index again. You may need to delete existing index files and run full index again either by
i) using UI - SSP Search config
ii) using stsadm commands
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm –o spsearch –action fullcrawlstop
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm –o spsearch –action fullcrawlstart
5. You should also check if the file file ext is included in files to be indexed (in SSP Search config). Note that not all files are indexable or included in indexing.
6. Additionally, check the search visibility under Site Actions > Site Settings > Search visibility to check whether that particular site and its contents are included in crawling
7. It can be a crawler access issue. If yes, Reset the rights of the crawler account to the content database thru SQL Enterprise Mgr/Mmgt Studio and/or check the check web application policy whereby the crawl account must have "Full Read" access.
Subscribe to:
Posts (Atom)