2007-12-31
Online Open Port Check Tool
This is really useful for both security and usability (P2P).
http://www.canyouseeme.org/
2007-08-31
Recursive batch delete command
We could write a console app with the following:
SPListItemCollection listItems = list.Items;
for (int id = 8; id <= listItems.Count; id++)
{
try {
listItems[id].Delete();
Console.WriteLine("Deleting " + id.ToString());
}
catch(Exception ex){ }
}
list.Update();
Now sit back and watch the numbers tick by... or you could what is widely considered the fastest way in SharePoint (WSS) to perform the operation, to use 'ProcessBatchData' as it avoids the Object Model and is considerably faster.
Here is some example code which will remove items from a SharePoint list.
StringBuilder oSBDelBat = new StringBuilder();
oSBDelBat.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><batch>");
foreach (SPListItem item in CurrentList.Items)
{
oSBDelBat.Append("<method>");
oSBDelBat.Append("<setlist scope="\">" + CurrentList.ID + "</setlist>");
oSBDelBat.Append("<setvar name="\">" + Convert.ToString(item.ID) + "</setvar>");
oSBDelBat.Append("<setvar name="\">Delete</setvar>");
oSBDelBat.Append("</method>");
}
oSBDelBat.Append("</batch>");
try
{
SPContext.Current.Site.RootWeb.ProcessBatchData(oSBDelBat.ToString());
}
catch (Exception ex)
{
Console.WriteLine("Delete failed: " + ex.Message);
throw;
}
2007-08-28
Deploying a dll to the GAC and recycling the application pool
How do we do this?
1.- Open the properties window for your project... solution explorer> right click project name > select properties.
2.- Click "Build Events".
3.- Paste
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil" -i "$(TargetPath)" } C:\Recycle.vbs
in to the "Post-build event command line" field.
4.- Create a new text file with the following script:
strAppPoolName = "Sharepoint - 80"
strComputer = "."
Set objWMIService = GetObject("winmgmts:{authenticationLevel=pktPrivacy}\\"& strComputer & "\root\microsoftiisv2")
Set colItems = objWMIService.ExecQuery("Select * From IIsApplicationPool Where Name = 'W3SVC/AppPools/" & strAppPoolName & "'")
For Each objItem in colItems
objItem.Recycle
Next
Wscript.echo "Recycle Completed"
5.- Save as C:\Recycle.vbs
2007-07-31
Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561
Cause: DLL's that access databases require at least the WSS_Medium security policy in the web.config file.
If you receive a security message from the web part, it's usually the trust element in the web.config file.
You could also have a dll outside the GAC that's trying to access some part of the SharePoint Object Model.
Fix:
There's a couple of ways to resolve this issue.
- Put you dll in the GAC. I don't like putting limited use web parts in there and managed code for InfoPath doesn't like it.
- Open wss_mediumtrust.config & wss_minimaltrust.config usually (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\) look in your web.config file for the exact path.
Find in wss_mediumtrust.config:
<SecurityClass Name="SqlClientPermission" Description="System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
Copy and paste it in to the <SecurityClasses> node of wss_minimaltrust.config.
In the PermissionSet section of this configuration file, add the following:
Find in wss_mediumtrust.config: <IPermission class="SqlClientPermission" version="1" Unrestricted="true"/>
Copy and paste it in to the a <PermissionSet> node of wss_minimaltrust.config. That about covers it. - You could also set the trust level to "wss_mediumtrust" or create a custom trust level. Google it...
The file or folder name contains characters that are not permitted. Please use a different name.
OK had this issue again and its caused by the SP dll not finding the master page defined in the aspx page.
The fix is to make sure it can.
Options:
2007-06-21
Using ASP.Net user controls ASCX in MOSS/WSSv3
Chris Johnson has posted a great article on using ASP.Net ASCX user controls in MOSS/WSSv3. I have been recently creating custom controls in Visual Studio (i.e. Control Classes not ASCX). To use these I add the controls to the GAC and then add an entry to the web.config to make it a safe control. The benefit of the ASCX model is that you can develop the user control in a more visual manner.
The ASCX controls can be used in MOSS/WSSv3 via the following method:
1. Create a Directory called “usercontrols” in the root of your sharepoint web site on the file system E.g. C:\Inetpub\wwwroot\wss\VirtualDirectories\moss.litwareinc.com80\UserControls
2. Open IIS manager and in the root of your SharePoint site create a VirtualDirectory called “_controls” and point it to that newly created directory.
3. Put your user control in that newly created directory on the filesystem
4. Open the web.config file and add the following:
<SafeControl src="~/_controls/*" mce_src="~/_controls/*" IncludeSubFolders="True" Safe="True" AllowRemoteDesigner="True" /">
5. In your ASPX page add the following:
<%@ Register src="~/_controls/SomeControl.ascx" mce_src="~/_controls/SomeControl.ascx" TagName="somecontrol" TagPrefix="uc2" %">
And…
<uc2:somecontrol id="mycontrol1" runat="server"></uc2:somecontrol>
6. Run your ASPX page and your control should render correctly.
2007-05-28
Launch ASP.NET Web Site Administration Tool without VS
Thank you Phil!
Create a batch file with:
@echo off
SET FrameWorkFolder=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
SET VFolder=Asp.NetWebAdminFiles
SET Port=8099
SET App=/Portal
SET AppPath=C:\Projects\SIS\Portal\
explorer "http://localhost:%Port%/%VFolder%/default.aspx?applicationPhysicalPath=%AppPath%&applicationUrl=%App%"
%FrameWorkFolder%\WebDev.WebServer.EXE /port:%Port% /path:%FrameWorkFolder%\%VFolder% /vpath:/%VFolder%
2007-05-14
Adding to web.config across farm with SPWebConfigModification
Use the WebConfigModifications property of the SPWebApplication or SPWebService class to get the collection of web.config modifications either in the Web application or in all Web applications within the Web service.
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
class Program {
private const string ScriptResourceHandler = @"<add verb=""GET,HEAD"" path=""FOO.bar"" type=""System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions"" validate=""false""/>"
static void Main(string[] args)
{
SPSite siteCollection = new SPSite("http://localhost");
SPWebApplication webApp = siteCollection.WebApplication;
SPWebConfigModification modification = new SPWebConfigModification();
modification.Path = "configuration/system.web/httpHandlers"
modification.Name = "Example"
modification.Value = value;
modification.Owner = "ExampleOwner"
modification.Sequence = 0;
modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
webApp.WebConfigModifications.Add(modification);
// .Remove doesn't remove it from the web.config, BTW... :(
webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
}
}
2007-04-27
Activating Site Collection Feature: Office SharePoint Server Publishing Infrastructure - Access Denied
Cause:
This is caused by the Application Pool user account for the web application not having rights to access the feature resource.
Fix:
There are a couple ways you can fix this; either give the user higher rights or more easily:
1. Open IIS Admin.
2. Location the Web Site for your WSS web application.
3. Goto to the properties and select the ‘Home Directory’ tab.
4. Change the AppPool to be the same as Central Administration.
5. Stop/Start the Web App.
6. Activate the Publishing Infrastructure feature on your site.
7. Change to AppPool back to the original.
8. Stop/Start the Web App.
2007-03-31
Configuring Forms Authentication with AD (Scott Hillier)
Forms authentication allows you to configure a SharePoint page as a login form instead of utilizing Windows authentication directly. SharePoint supports many different providers for authenticating users against other data stores such as SQL Server or an LDAP service. In this exercise, you will make use of the ActiveDirectoryMembershipProvider to configure Forms authentication against Active Directory. In this scenario, users will enter their Windows credentials into the login form to gain access to the secure site.
Follow these steps to set up Forms authentication:
1. Log in to <machine> as the local administrator.
2. Open the File Explorer and navigate to \Inetpub\wwwroot\wss\VirtualDirectories.
3. Under the VirtualDirectories folder, identify the subdirectory that is associated with your site and the folder associated with the Central Administration site.
4. Open the web.config file for both the extranet site and the Central Administration site. The provider information must be added to both files.
5. Directly above the <system.web> tag in both files, add the following section to define a connection to Active Directory:
<connectionStrings>
<add name="ADService" connectionString="LDAP://vspdc.domain.
local/DC=domain,DC=local" />
</connectionStrings>
6. Directly underneath the <system.web> tag in both files, add the following section to utilize the ActiveDirectoryMembershipProvider as the authentication provider:
<membership defaultProvider="AD">
<providers>
<add name="AD"
type="System.Web.Security.ActiveDirectoryMembershipProvider,
System.Web, Version=2.0.0.0, Culture=neutral,
PublickeyToken=b03f5f7f11d50a3a"
connectionStringName="ADService"
connectionUsername="DOMAIN\Administrator"
connectionPassword="P@ssw0rd"
connectionProtection="None"
attributeMapUsername="sAMAccountName" />
</providers>
</membership>
7. Save and close both files.
8. Select Start > Run. In the Run dialog, type iisreset and click the Open button.
9. Open the Central Administration site by selecting Start Administrative Tools SharePoint 3.0 Central Administration.
10. In the Central Administration site, click the Application Management tab.
11. Under the Application Security section, click the link titled Authentication Providers.
12. If the correct web application is not already selected, drop down the Web Application selection list and click Change Web Application. Then click the link for the initial web application that you set up.
13. On the Authentication Providers page, click the Windows link associated with the Extranet zone.
14. On the Edit Authentication page, select Forms as the Authentication Type.
15. In the Membership Provider Name field, type AD, which is the name of the provider as it appears in the web.config file.
16. Click the Save button.
17. In the Central Administration site, click the Application Management tab.
18. Under the Application Security section, click the link titled Policy for Web Application.
19. If the correct web application is not already selected, drop down the Web Application selection list and click Change Web Application. Then click the link for the initial web application that you set up.
20. Click the Add Users button.
21. On the Add Users page, select Extranet from the zone list.
22. Click the Next button.
23. On the Add Users page, type Administrator into the Users field and click the Check Names image button.
24. Under the Choose Permissions section, check the box labeled Full Control – Has Full Control.
25. Click the Finish button.
Delete shared service provider
System Event Log: The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID
{61738644-F196-11D0-9953-00C04FD919C1}
to the user <machine>\SPSharedServicesPool SID (S-1-5-21-974288755-3100551457-677853593-1023). This security permission can be modified using the Component Services administrative tool.
With the registry editor open, ensure that your cursor is on the computer at the beginning of the tree (make sure you are not in the middle of some previous edit session in the registry editor).
Edit-->Find and paste in the GUID. It'll stop at the application entry - and you will want to note the application name on the right side pane. In this example, it was the IIS WAMREG admin service that popped up.
Now, open Component Services (typically, from the server - Start-->Administrative Tools-->Component Services), expand Component Services, Computers, My Computer, DCOM Config. Scroll down and find the application (IIS WAMREG in this case). Right-Click-->Properties and select the Security tab. You'll have some options here - the first block Launch and Activation Permissions - ensure that the Customize radio button is selected, and click Edit. Now, add your service account - giving it launch and activate - and in some requirements - remote launch / activate permission.
Restart IIS and continue on.