SharePoint Impersonation
Submitted by sami on Tue, 01/19/2010 - 20:46Completely copied from this site. Useful stuff and I'm glad he posted the code with all of the comments.:
http://www.sharepoint-tips.com/2007/03/sample-event-handler-to-set-permi...
using System;
using System.Globalization;
using System.ComponentModel;
using System.IO;
using System.Data;
using System.Text;
using System.Xml;
using System.Collections;
using System.Configuration;
using System.Diagnostics;
using System.Web;
using System.Security;
using System.Security.Policy;
using System.Security.Principal;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using Microsoft.SharePoint;
namespace SharePointTips.SharePoint.Samples.EventHandlers
{
///
/// This is the event receiver that traps the item added event of the sharepoint list it is attached to.
///
class ListItemSecuritySetter:SPItemEventReceiver
{
#region constants
///
Google maps API error
Submitted by sami on Mon, 11/02/2009 - 10:29I was getting the following pop up error on my Google maps page:
"The Google Maps API key used on this web site was registered for a different web site. You can generate a new key for this web site at http://code.google.com/apis/maps/."
Even after generating a new key, the pop up still appeared. The site is using the sugurim control. The fix was to change my web.config setting for the API key. I had named it "GoogleMapKey". I changed it to "googlemaps.subgurim.net" and it started working.
SharePoint Sign In As Another User Caching Old User Name
Submitted by sami on Mon, 10/12/2009 - 14:00On a SharePoint application, I was using "Sign in as Another User", but the previous user's name showed on the site until I clicked Refresh at least once, sometimes more.
To fix this, I followed advice I found here: http://stackoverflow.com/questions/168946/iis-returning-old-user-names-t...
I went to the Local Security Settings (in Administrative Tools) and browsed to: "Local Policies --> Security Options" and picked "Interactive logon: Number of previous logons to cache (in case domain controller is not available)" and set that to 0. Then, I did an IIS Reset. Seems to have fixed it.
Changing the web part list view in SharePoint
Submitted by sami on Wed, 10/07/2009 - 11:13I needed to change the list view of a web part that had already been deployed to 1700 site collections programmatically. Thanks to theses posts:
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thre...
and
http://community.zevenseas.com/Blogs/Robin/archive/2008/11/16/creating-a...
I came up with a solution:
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite spSiteTest = new SPSite(sURL))
{
using (SPWeb spWebTest = spSiteTest.OpenWeb())
{
SPFile targetPage = spWebTest.GetFile("Pages/MyPage.aspx");
SPLimitedWebPartManager webpartManager = null;
Programmatically add web parts to the SharePoint Web Part Gallery
Submitted by sami on Thu, 09/10/2009 - 11:46It's a simple matter of uploading the files to the Web Part Gallery list, as shown here:
http://www.customware.net/repository/display/SharePoint/SharePoint+-+Pro...
string url_Site = sSite;
using (Microsoft.SharePoint.SPSite site = new Microsoft.SharePoint.SPSite(url_Site))
{
Microsoft.SharePoint.SPList ctg_WebParts = site.GetCatalog(Microsoft.SharePoint.SPListTemplateType.WebPartCatalog);
FileInfo file = new FileInfo(@"c:\webpartfile.webpart");
FileStream stream = file.Open(FileMode.Open, FileAccess.Read);
SPFolder root = ctg_WebParts.RootFolder;
SPFile dwpFile = root.Files.Add("webpartfile.webpart", stream);
dwpFile.Update();
stream.Close();
stream.Dispose();
}
Attribute is not declared as a dependency
Submitted by sami on Wed, 08/19/2009 - 12:20Thanks to this post: http://marcusoh.blogspot.com/2006/12/miis-attribute-not-defined-as-sourc...
I was getting a similar error:
icrosoft.MetadirectoryServices.AttributeNotDefinedAsSourceException: Attribute "mailNickName" is not declared as a dependency.
at Microsoft.MetadirectoryServices.Impl.EntryState.GetAttribute(String attributeName, IMacroCollectionBase collection)
at Microsoft.MetadirectoryServices.Impl.CSEntryImpl.get_Item(String attributeName)
at Microsoft.Exchange.DirSync.RulesExtensions.RulesCommon.IsAttributePresentInCSEntry(CSEntry csentry, String attrName)
at Microsoft.Exchange.DirSync.RulesExtensions.RulesCommon.GetOnPremiseObjectType(CSEntry csentry)
at Microsoft.Exchange.DirSync.RulesExtensions.MAExtensionObject.Microsoft.MetadirectoryServices.IMASynchronization.MapAttributesForImport(String FlowRuleName, CSEntry csentry, MVEntry mventry)
GalSync and custom rules extensions
Submitted by sami on Thu, 07/30/2009 - 15:03When creating a custom rules extension, you often don't want to write code to handle every function MIIS requires for the MA.
A trick I found is to use reflection to grab a dll, such as the Microsoft.Exchange.Dirsync.RulesExtensions.dll. You can create an object using that and then call the OOB functions for areas you do not want to customize in your custom rules extension. assem = [Assembly].LoadFrom(fileName)
Additionally, if you want to call a PowerShell command in your rules extension project, try the information provided here: http://groups.google.com/group/microsoft.public.windows.powershell/brows... and be sure to remember that referencing the System.Management.Automation.Runspaces.dll requires manually editing the .vbproj or .csproj,, as described in an earlier post.
Adding System.Management.Automation.Runspaces to a Project
Submitted by sami on Thu, 07/30/2009 - 14:57In order to reference the System.Management.Automation.Runspaces in a Visual Studio project, you need to open the .csproj or .vbproj in Notepad. In the "ItemGroup" node, add a new value at the end:
<Reference Include="System.Management.Automation.Runspaces" />
The post here explains more: http://74.125.47.132/search?q=cache:wCk4wwQ7eNwJ:www.eggheadcafe.com/sof...
Enabling the internet on virtual PC
Submitted by sami on Mon, 07/06/2009 - 16:57Choose the Shared Option in network adapters on the Virtual PC settings.
When you are on the virtual machine, you may need to go to the support tab of the "Local Area Connection Settings" and choose to "Repair".
ipconfig /release and /renew are useful...
UPDATE FOR WINDOWS 7
I had to change the Settings on my Windows 2003 guest VM from Shared Networking to the network of my local wired connection.
Then, I had to change the Windows 2003 Local Area Connection for TCP/IP to automatically obtain DNS. This post details another approach that may help as well: http://www.tipandtrick.net/2008/fix-virtual-pc-2007-shared-networking-na...
SharePoint Expiration Date Issue
Submitted by sami on Fri, 06/26/2009 - 11:55The public update to fix this issue is available for download.
Post URL is here: http://blogs.msdn.com/sharepoint/archive/2009/06/25/service-pack-2-updat...
Service Pack 2 Update.
The public update for the Service Pack 2 expiration date issue is now available for download.
The update can be applied before or after Service Pack 2 installation. If the update is applied prior to installing Service Pack 2 it will prevent the expiration date from being improperly activated during installation of Service Pack 2, if it is applied after Service Pack 2 it will remove the expiration date incorrectly set during installation of Service Pack 2.
The update is applicable to all of the products that this issue affected (see the list in the KB linked below).
Installation instructions and download links for x86 and x64 are available in this KB: http://support.microsoft.com/kb/971620



