Friday, June 27, 2008

How to get a top level domain name

ICANN has indicated they will allow companies to submit proposals for top level domain names or TLD names. It looks like the initial cost will be in the six figures to obtain one of these bad boys and the process looks like it has been well planned. See link below.

http://www.praxagora.com/andyo/professional/icann_tld_approval.html

I can only hope it is that easy.

Thursday, June 26, 2008

Unable to instantiate event handler Request registry access is not allowed

I've create a custom SharePoint document library event handler and have attached it to a document library, however when I do something to kick off the handler, nothing happens and this error gets recorded on the server event log. Looking through some (I mean very few posts) I found that the document library event handlers run as the app pool account of the SharePoint site.

So if the app pool account doesn't have access to the registry then it's probably possible that this is the reason registry access is not allowed. To fix this I gave the app pool account admin privledges on the server and retried. This fixed the problem.

Event manager error: Unable to instantiate event handler (assembly "EventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=", class "EventHandler"), or report event for ".xml" in ". Requested registry access is not allowed.

SPFile.CopyTo SPFile.MoveTo How to move a file across SharePoint sites programmatically

I think we've all tried SPFile.CopyTo(destUrl) or SPFile.MoveTo(destUrl) and have quickly found that it doesn't allow us to move that file across SharePoint sites. How then can we copy a file from one site to the other programmatically?

Well we need to use the SPFileCollection.Add method as demonstrated below. Sure it's not as easy as a one liner but it gets the job done just the same and more importantly it lets you do it between sites and site collections.


//copy the file to another site document library

using (SPSite spSite = new SPSite("http://destination site url/"))

{

string destinationUrl = "some destination url/" + spFile.Name;

SPFileCollection spFiles = spSite.AllWebs["site relative url"].GetFolder("Doc Lib Name").Files;

byte[] bFile = spFile.OpenBinary(); //spFile is the source file

spFiles.Add(destinationUrl, bFile, true);

}

Basically open up your destination site, get the file collection object from the source document library, add the binary representation of the file to the file collection object and that's it.

Wednesday, June 25, 2008

The selected file was not found - InfoPath Form Services

I created an internal InfoPath form that was hosted in the InfoPathViewer Web Part and put a file attachment control on it. I kept getting "the selected file was not found" when attaching a document to the form. To solve this I needed to add a Content Editor Web Part with the following code in the source. This encoding is crucial for the ability to attach attachments to InfoPath forms hosted on Forms Server or within the InfoPathViewer Web Part.

script type="text/javascript" aspnetForm.encoding = "multipart/form-data"; /script

Tuesday, June 24, 2008

Create a Save As dialog box in InfoPath

Just pop the following code into your VSTO project for the button click event.

FileDialog oDialog = new SaveFileDialog();
oDialog.DefaultExt = "xml";
oDialog.Filter = "InfoPath Form (*.xml)*.xml";
if(oDialog.ShowDialog() == DialogResult.OK)
{
string sFilename = oDialog.FileName;
this.SaveAs(sFilename);
}

Update SPListItem without changing Modified Date

SPListItem.SystemUpdate Method (Microsoft.SharePoint)


Updates the database with changes that are made to the list item without effecting changes in the modified time or modified by fields.

Office 2003 Web Parts (Components) Security Prompts

By default these two warning prompts will display because of a setting in IE.

This website uses a data provider that may be unsafe. If you trust the website, click OK, otherwise click Cancel.

This website is using your identity to access a data source. If you trust this website, click OK to continue, otherwise click Cancel.

To get rid of these Enable Access data sources across domains, instead of Prompt set it to Enable. And Automatic logon with current user name and password.