How to determine the correct (case sensitive) URL for a SharePoint site

  • How to determine the correct (case sensitive) URL for a SharePoint site Goyuix

    Problem: Creating a site column using the SharePoint API (Object Model) with incorrect case in the URL for the SPSite or SPWeb object will cause the new column to throw an exception if an attempt to edit it is made through the Site Columns Gallery.

    SharePoint is generally very tolerant of accepting a URL in a case-insensitive fashion, however there are a few cases where it completely breaks down. For example, when creating a site column it somehow stores and uses the URL when it was created, and when trying to edit the field definition through the Site Column Gallery (fldedit.aspx page in the LAYOUTS) you end up throwing the error below.

    Value does not fall within the expected range.
    at Microsoft.SharePoint.SPFieldCollection.GetFieldByInternalName(String strName, Boolean bThrowException)
    at Microsoft.SharePoint.SPFieldCollection.GetFieldByInternalName(String strName) 
    at Microsoft.SharePoint.ApplicationPages.BasicFieldEditPage.OnLoad(EventArgs e) 
    at System.Web.UI.Control.LoadRecursive() 
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 

    How can I reliably get the correct URL for a site/web? The SPSite.Url and SPWeb.Url properties seem to return back whatever case they are instantiated with.

    In other words, the site collection is provisioned using the following URL: http://server/Path/Site

    Then, if I create a new Site Column using the SharePoint object model and happen to use http://server/path/site when instantiating the SPSite and SPWeb objects, the site column will be made available but when trying to access it through the gallery the error above is generated. If I correct the URL in the address bar, I can still view/modify the definition for the SPField in question, but the default URL that is generated is bogus.

    Clear as mud?

    Example code: (this is a bad example because of the case sensitivity issue)

    // note: site should be partially caps: http://server/Path/Site
    using (SPSite site = new SPSite("http://server/path/site")) {
      using (SPWeb web = site.OpenWeb()) {
        web.Fields.AddFieldAsXml("..."); // correct XML really here

    Disclaimer: Shameless re-ask from StackOverflow

  • I tend to use the SPContext to retrieve the Web and Site objects where applicable.

    However, you can only use this where your code has a context, so within Web Parts and application pages, and this rules out command line and timer job stuff.

    Basically, I try to avoid hard-coding a URL in code whenever I can avoid it, as it makes the code less scalable and adaptable. What context does your code run in? Event/Feature Receiver, Web Part, etc?

  • I haven't tested these but you could try getting the properly cased url from the various SharePoint web services such as although if the case isn't correct in the SPSite and SPWeb objects then they may not be correct there.

    Alternatively you could create your own web service that takes the url and returns the proper cased url by accessing the current context in the web service. A lot of hoops to go through for something that seems like it should be able to done easier though.

list column
Related questions and answers
  • that attribute names are case-sensitive. (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebClients\Profile\client.config line 56) ---> System.Configuration.ConfigurationErrorsException: Unrecognized attribute 'allowInsecureTransport'. Note that attribute names are case-sensitive. (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebClients\Profile... attribute 'allowInsecureTransport'. Note that attribute names are case-sensitive. (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebClients\Profile\client.config line 56

  • I am using SharePoint 2007 Server x64 on Windows Server 2008 x64. I create a new SharePoint web application with a new site collection at the root of the web application. I select the template "publishing portal" for the site collection. I have also enabled anonymous access. Now the basic function is fine, except that I do not know how to change the first front page (i.e. the page showed to end users who have not logged in yet) of the site. Here is a screen snapshot. Any ideas how to edit this page? Publishing home page BTW: I have tried to edit

  • I have a webpart i build using WSpBuilder and it works OK. When i use Deploy from Visual Studio it installs the WSP sharepoint and add the webpart to the webpart gallery. But it seems the feature...(SPFeatureReceiverProperties properties) { SPSite site = null; try { site = properties.Feature.Parent as SPSite; using (SPWeb web = site.RootWeb...; </File> </Module> </Elements> But when i go to the site features i can see the feature but when i activate it it does puts the webpart in the gallery but when i

  • = ""; SPSecurity.RunWithElevatedPrivileges(delegate { using (SPSite site = new SPSite(server)) { SPServiceContext context...I have been developing on SP 2010 for a while now. Mostly I have been working with the Client Object Model. Though I am at a point where I need to read out the UserProfiles from inside SharePoint. I see no other way to do this than to make a custom WCFService and deploy it to SharePoint. So that is what I did. I made an "Empty SharePoint Project" and added the mapped "ISAPI" folder. The code

  • Module: I think this is the most likely path forward, however it seems to always want to provision a file to the site. For example, if I want to add a web part to the home page (default.aspx... it to the default.aspx home page. I would be happy either way. Note: I want to be able to activate this on existing site, I dont want to create a new Site Definition. Here is what I have tried: Feature Receiver..., the only Neat way I can see through it is some sort of "Configuration" page, which then does it via the Web Services. But this is a pain, with the user having "Activate" the feature and then "Activate

  • Has anybody upgraded an old custom field type to use the new XSL transform in SharePoint 2010? I have a multi-column field type, and want the Display pattern to render the 2nd "column", which...;/RenderPattern> In WSS 3.0, this would render the 2nd column in the field as a hyperlink in the LVWP, which is what I want. In SharePoint 2010, I tried adding TRUE to my field type definition, but that ends up rendering the actual anchor tag, as opposed to a clickable hyperlink: <a href=""></a> So then I tried creating a XSL transform, since

  • There have been several questions asked on this site regarding the best way to provision sites and lists (definition schemas vs. templates vs. the object model vs. the web interface vs. provisioning providers). I have even responded to some of them. Custom site definition to define a custom site with a subsite Best way to build out and configure multiple lists When to use Custom Site... changes to a site definition to the sites that have been created from it. Changes to web templates only affect new sites that are created from them. My understanding was that this is not the case

  • I have a new SharePoint 2010 server farm that I'm trying to configure. Installation went fine. But I'm having trouble getting the user profiles to import. I've created the User Profile service... because the client side timeout limit was exceeded." In the SharePoint logs, when I filter based on the correlation ID, I get the following messages: Name=Request (POST:http://poc-bi-sp:8080/_layouts... of permissions --- {1}. Available parameters: System.ServiceModel.EndpointNotFoundException: Could not connect to http://poc-bi-sp:5725/ResourceManagementService/MEX. TCP error code 10061: No connection could

  • I have a Silverlight 4 Beta application where I'd like to use the SharePoint object model to upload a document to a SharePoint site - should be simple enough, except an exception is thrown at: using (SPSite siteCollection = new SPSite(siteCollectionUrl)) The Web application at could not be found. Verify that you have typed the URL correctly. If the URL... using some controls that only work in x86. The installed SharePoint version is x64. I've read about people seeing this exception when trying to use the SharePoint object model to hit a x64 SharePoint

Data information