Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

When we create a new web application in SharePoint from Central Admin,we see that a free port is automatically populated. Is there a good way to determine the free ports like SharePoint does?

share|improve this question

1 Answer 1

The way SharePoint does it is to generate a random number, which it then tests to see if the port is in use on the local machine.

If you have .NET Reflector, check out SPGlobalAdmin.GenerateRandomPort(int initialValue) in

Assembly: Microsoft.SharePoint.dll

Namespace: Microsoft.SharePoint.Administration

share|improve this answer
    
Thanks for the answer. Is there a way via code to see if any port is free on the machine –  SP.NET Mar 29 '12 at 8:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.