1

I am having my project(folder format) in IIS, i want to convert that folder into application (like right click->Convert to application), i want to perform this in C# code, i am using .net 2.0. i followed this link Using ServerManager to create Application within Application, but i don't know

Site site = serverManager.Sites.First(s => s.Id == 3);

What is that? when i try to add that code i am getting error called: microsoft.web.administration.sitecollection does not contain a definition for first

Please do some replies...

Community
  • 1
  • 1
Karthik.M
  • 67
  • 11

1 Answers1

3

What is that?

It's LINQ and it is not available in .NET 2.0. You will need to use .NET 3.5 or later and have the System.Core assembly referenced in your project and the System.Linq namespace added to your using directive in order to bring the .First() extension method into scope.

If you cannot upgrade to a more recent version of .NET you could achieve similar results with the following:

Site site = null;
foreach (var s in serverManager.Sites)
{
    if (s.Id == 3)
    {
        site = s;
        break;
    }
}
if (site == null)
{
    throw new InvalidOperationException("Sequence contains no elements that match the criteria (Site Id = 3)");
}

// at this stage you could use the site variable.
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I want to use .net 2.0 to achieve this task, i don't want .net 3.5 to proceed, can i get any other samples to achieve this task in .net 2.0? – Karthik.M Apr 05 '13 at 06:19
  • Sure, you could search the Sites collection for the element that matches your criteria. I have updated my answer to provide an example. – Darin Dimitrov Apr 05 '13 at 06:22
  • Thank you so much, now i can convert to application, when i try to browse that application "HTTP Error 403.18 - Forbidden The specified request cannot be processed in the application pool that is configured for this resource on the Web server." i am getting this error what will be the problem? – Karthik.M Apr 05 '13 at 06:36