Tuesday, May 3, 2011

Delete a Web that doesn't exist.

While setting up a test environment I was attempting to set up many different types of sites for testing various things when I ran into a strange bug in SharePoint.

I was creating a subsite under a blank site template and saw the option for "News Site" so I selected it and got an error saying that the Publishing Feature was not enabled at the site collection level.

Fine. So, I went and activated it and then attempted to create the site again and I got the error:

The Web site address "/mpsite/news" is already in use

Ok, so the site must have been created anyway so I try to visit the URL and get:

The webpage cannot be found

Fine. So, obviously it errored in the middle of the site creation so I'll just delete it via STSADM. Wrong:

There is no top-level Web site named "http://server/mpsite/news/".

So, the site is listed in the sites and workspaces list, but doesn't really exist and can't actually be deleted.

How do I get rid of it from the Sites and Workspaces listing?

From stackoverflow
  • Have you tried http://server/mpsite/news/_layouts/deleteweb.aspx ?

    Or maybe the "Content and structure" (http://server/mpsite/_layouts/sitemanager.aspx) link from site actions?

    webwires : Cool, going directly to the deleteweb.aspx worked ... never would have guessed, good advice.
  • You've run into one of the lovely undocumented "features" of SharePoint - site templates get applied after the site gets created in a seperate, descrete step. This means that potentially, a site can "exist" (as far as the content database is concerned) without template, which leaves you with a site you can't browse to, but still sorta "exists" in SharePoint purgatory (I've actually written a couple of hacks that involve relying on this "feature").

    It looks to me like you may have run into one such situation - when you went to go create your site, I'm guessing that you got the error before the template was applied to your news site.

    The way I've fixed similar problems in the past has been to use SharePoint Designer to delete the sites - since it looks straight into the content database for what does and doesn't exist, it might do the trick for deleting your rouge news site.

    Hope this helps!

Stackoverflow-like login system in Rails?

What's the best (easy) way to implement a login/authentication system on a Rails web-app that looks and works like the Stackoverflow system?

I realize that it's basicly OpenID, but Stackoverflow handles integration with multiple providers.

Is there a easy way to this on Rails? Or do we have to hack restfull_auth or authlogic to do that?

From stackoverflow
  • Ryan has a decent railscast about this.

  • http://rubyforge.org/projects/ruby-openid/

    This may provide you with a solution. Also look at http://leancode.com/openid-for-rails/ for some resources and recommendations for OpenID on rails.

    This also looks promising, although I haven't seen the documentation. You might want to check it out.

  • Stackoverflow doesn't really do anything special for specific providers. It just takes an OpenId and then transfers the browser to the url processes it.

    You might want to check out this blog entry on integrating OpenId into your rails application:

    http://www.danwebb.net/2007/2/27/the-no-shit-guide-to-supporting-openid-in-your-applications

  • I believe StackOverflow uses the OpenID Selector, which for the visual effect is all HTML and Javascript, so you should be able to easily apply it to your Rails app that already uses a Ruby OpenID library.

    Javier : Does the Ruby OpenID library support account providers like Google and Yahoo (as does OpenID Selector)?
    rubenfonseca : As far as I tested it, it works with all the major openID providers, including google and yahoo!
  • Hi, I've just implemented what you're looking for in an example application:

    http://openid-example.joontos.ch

    (check out the link to the source code)

    rubenfonseca : excellent example! thank you!
    piemesons : @Javier its gone :-(

Hosting CLR versus using ClrCreateManagedInstance - what are the benefits?

I have successfully implemented interop beftween Win32 application and managed .Net dll as described here. But I also read here that it is possible to host the entire CLR inside of the unmanaged process.

So my question is: why would you do that? It is somewhat more complex than just use an object - what benefits you gain for this price of increased complexity?

Edit: what I understood from 2 first answers, is that you get the possibility to customize the CLR for your needs - meaning if you're writing a simple business app, you'll never need to host. Hosting is for system-heavy stuff, like browser or SQL Server.

From stackoverflow
  • You may have a legacy application and want to allow 3rd parties to the use the facilities of .net from within your application but particularly in a controlled manner such as controlling where assemblies are loaded from. Here is an example.

    Sergey Aldoukhov : Good link, thanks. Still, my question was more around of why you need more control.
  • Microsoft SQL Server uses it extensivly to replace the security, assembly loading, memory management, thread management and what not. A good book about this subject is "Customizing the Microsoft .NET Framework Common Language Runtime".

  • Hosting the CLR is generally not something you do to interop between managed code and Win32. there are generally 3 methods of interop:

    • Runtime Callable Wrapper (RCW) - call a COM object from .NET
    • COM Callable Wrapper (CCW) - make a .NET object appear as a COM object
    • P/Invoke

    These have been supported since the first version of .NET. The whole point of hosting the CLR is to allow you to deeply embed .NET code inside an unmanaged application. For example, there is a module that can host .NET in Apache on Win32 allowing it run .aspx pages.

    Similarly, the SQL Server wanted a way for people to write extended stored procedures and functions with managed code. In the past you could write these in C/C++, but if they hosted the CLR they could actually allow people to write these with C#. The work to get the CLR into a state were it could be safely embedded really pushed out the timelines, and so things like control over memory and security were born. SQL Server has some serious stability requirements and you can't have .NET rocking the boat.

    The hosting API changed significantly from .NET 1.x to 2.x but has been more stable since the 2.0 CLR has lived through .NET 3.0, 3.5 etc.

XmlInclude or SoapInclude

I am developing a webservice that returns arrays of classes I define within the webservice. When I test it, I get: "System.InvalidOperationException: The type WebSite+HostHeader was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."

Here is part of the code:

[WebService(Namespace = "http://WebSiteInfo.Podiumcrm.com/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class WebSite : System.Web.Services.WebService { public class WebSiteEntry { public string SiteName = ""; public string Comment = ""; public string IISPath = ""; public int SiteID = 0; public ArrayList HostHeaders;

    public WebSiteEntry()
    {
    }
}
public class HostHeader
{
    public string IPAddress = "";
    public int Port = 0;
    public string URL = "";

    public HostHeader()
    {
    }
}


[WebMethod(EnableSession = true)]
[TraceExtension(Filename = @"C:\DotNetLogs\WebSiteServices.log")]
public WebSiteEntry[] WebSites()
{...}

}

When I try: [WebService(Namespace = "http://WebSiteInfo.Podiumcrm.com/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [XmlInclude(typeof(WebSiteEntry))] [XmlInclude(typeof(WebSiteProperty))] [XmlInclude(typeof(HostHeader))]

public class WebSite : System.Web.Services.WebService {...}

I get: The type or namespace name 'XmlInclude' could not be found (are you missing a using directive or an assembly reference?)

Points the the person who can give me the incantation that both compiles and executes!

Thanks...

From stackoverflow
  • For shits and giggles, add the [Serializable] attribute to your HostHeader class:

    [Serializable]
    public class HostHeader
    {    
        private string _ipAddress = "";
        private int _port = 0;
        private string _url = "";
    
        public string IpAddress { get { return _ipAddress; } set { _ipAddress = value; } }
    
        public int Port { get { return _port; } set { _port = value; } }
    
        public string Url { get { return _url; } set { _url = value; } }
    
        public HostHeader()
        {
        }
    }
    

    That should ensure that your class is XML Serializable.

    alexdej : Actually, the XmlSerializer ignores this attribute.
  • From the error you are receiving:

    The type or namespace name 'XmlInclude' could not be found (are you missing a using directive or an assembly reference?)

    It appears that you are missing the System.Xml.Serialization Namespace. You can fully qualifying the XmlInclude type, like this:

    System.Xml.Serialization.XmlInclude(typeof(WebSiteProperty))
    

    or add the namespace via the using directive:

    using System.Xml.Serialization
    

WPF WindowsFormsHost VS2008 Toolbox has grayed out all the Windows Forms controls

I'm trying to use WindowsFormsHost in a WPF app so I can use some Windows Forms components.

<Grid>
    <WindowsFormsHost>

    </WindowsFormsHost>
</Grid>

This all works ok with no errors, but when I go to drag a Windows Forms component from the toolbox in VS2008, they're all grayed out. In a way this makes sense as only the WPF components are available. But how do you drop a Windows Forms component onto a WindowsFormsHost if they're all grayed out and unavailable?

From stackoverflow
  • I don't think WPF designer supports Windows Forms components. You need to specify these in the XAML or in code. A simple example of how to add a WinForms button into a WPF application. Note that the button isn't visible on the design surface.

    <Window x:Class="DataTemplateBind.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        Title="Window1" Height="300" Width="300">
    
        <WindowsFormsHost Height="200" Name="windowsFormsHost1" Width="258" >
            <forms:Button Text="Waaa :("></forms:Button>
        </WindowsFormsHost>
    </Window>
    

    Note the added xmlns:forms namespace which isn't there by default.

    Mitch : Thanks Mikko, that did it. I was at the end of a long day and the frustration was setting in!

how to extract formating part from a string

How does one extract only the formatting part from a string. For example: if I have a string = "Warning: the error {0} has occurred. {1, 9} module has {2:0%} done." I would like to extract {0}, {1,9} and {2:0%} out into a sting array. Is there a regular expression or something that can be done other than my way of looping the string with Substring indexof '{' and '}' alternately?

From stackoverflow
  • Will some variant of "\{[^}]+\}" not work? Run it through finding the matches and substring'ing out from start to end of the match.

  • new Regex(@"\{[0-9:,% .]+\}");
    

    You may have to tweak/tune it to account for any additional formatting options that you haven't provided in your example.

  • In Java, the Matcher class takes a regex and will return all matching sub-strings.

    For example:

    String str = "Warning: the error {0} has occurred. {1, 9} module has {2:0%} done.";
    
    Matcher matcher = pattern.matcher( "{.*}");
    while (matcher.find()){
        String matched = matcher.group()
        \\do whatever you want with matched
    }
    
  • The following code is different from other answers in that it uses non-greedy matching (".*?"):

        private static void Main(string[] args) {
            const string input = "Warning: the error {0} has occurred. {1, 9} module has {2:0%} done.";
            const string pattern = "{.*?}"; // NOTE: "?" is required here (non-greedy matching).
            var formattingParts = Regex.Matches(input, pattern).Cast<Match>().Where(item => item.Success).Select(item => item.Groups[0].Value);
            foreach (var part in formattingParts) {
                Console.WriteLine(part);
            }
        }
    
    Terry_Brown : +1 I'd started writing something with named matches to help extract each part individually, but the above stopped me - really nice solution
    Colin Burnett : Except doing [^}] in between { and } prevents it from being greedy. Likewise on [0-9:,% .] that Jordan proposed. Ethan's is the only greedy one that will match "{0} ... {1}" from beginning to end.

How to programatically modify assemblyBinding in app.config?

I am trying to change the bindingRedirect element at install time by using the XmlDocument class and modifying the value directly. Here is what my app.config looks like:


<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">            
            ...
        </sectionGroup>      
    </configSections>
    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="MyDll" publicKeyToken="31bfe856bd364e35"/>
          <bindingRedirect oldVersion="0.7" newVersion="1.0"/>
        </dependentAssembly>
     </assemblyBinding>
    </runtime>    
...
</configuration>

I then try to use the following code to change 1.0 to 2.0

    private void SetRuntimeBinding(string path, string value)
    {
        XmlDocument xml = new XmlDocument();


        xml.Load(Path.Combine(path, "MyApp.exe.config"));
        XmlNode root = xml.DocumentElement;

        if (root == null)
        {
            return;
        }

        XmlNode node = root.SelectSingleNode("/configuration/runtime/assemblyBinding/dependentAssembly/bindingRedirect/@newVersion");

        if (node == null)
        {
            throw (new Exception("not found"));
        }

        node.Value = value;

        xml.Save(Path.Combine(path, "MyApp.exe.config"));

    }

However, it throws the 'not found' exception. If I back the path up to /configuration/runtime it works. However once I add assemblyBinding, it does not find the node. Possibly this has something to do with the xmlns? Any idea how I can modify this? ConfigurationManager also does not have access to this section.

From stackoverflow
  • Modifying Configuration Settings at Runtime By UsualDosage

    This article will demonstrate how to add, delete, and update key value pairs in an App.config file.

    http://www.codeproject.com/KB/cs/modconfigruntime.aspx

    esac : Not helpful. I already know how to modify it programatically at runtime. My problem is that it works for other areas, just not for assemblyBinding element.
  • I think the right Xpath syntax is:

    /configuration/runtime/assemblyBinding/dependentAssembly/bindingRedirect@newVersion

    (you have a slash too many).

    Or if this doesn't work you could select the bindingRedirect element (using SelectSingleNode):

    /configuration/runtime/assemblyBinding/dependentAssembly/bindingRedirect

    Then modify the attribute newVersion of this element.

    esac : Already been down this path, it complains of invalid token with bindingRedirect@newVersion. Second case, it complains that it could not find the path specified.
  • I found what I needed. The XmlNamespaceManager is required as the assemblyBinding node contains the xmlns attribute. I modified the code to use this and it works:

        private void SetRuntimeBinding(string path, string value)
        {
            XmlDocument doc = new XmlDocument();
    
            try
            {
                doc.Load(Path.Combine(path, "MyApp.exe.config"));
            }
            catch (FileNotFoundException)
            {
                return;
            }
    
            XmlNamespaceManager manager = new XmlNamespaceManager(doc.NameTable);
            manager.AddNamespace("bindings", "urn:schemas-microsoft-com:asm.v1");
    
            XmlNode root = doc.DocumentElement;
    
            XmlNode node = root.SelectSingleNode("//bindings:bindingRedirect", manager);
    
            if (node == null)
            {
                throw (new Exception("Invalid Configuration File"));
            }
    
            node = node.SelectSingleNode("@newVersion");
    
            if (node == null)
            {
                throw (new Exception("Invalid Configuration File"));
            }
    
            node.Value = value;
    
            doc.Save(Path.Combine(path, "MyApp.exe.config"));
        }
    
    esac : Just a note, I throw exceptions as this is part of an Setup Project and that is how the installer is notified of any errors. It would be better to have the method return true or false if the modification was made.
  • Sounds like you've got your configuration file tweak working now, but I thought you might still be interested in how to adjust binding redirects at run time. The key is to use the AppDomain.AssemblyResolve event, and the details are in this answer. I prefer it over using the configuration file, because my version number comparison can be a bit more sophisticated and I don't have to tweak the configuration file during every build.

  • awesome thread, saved me a ton of time.