SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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


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.