<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sharing The Point &#187; PowerShell</title>
	<atom:link href="http://www.mattjimison.com/blog/category/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mattjimison.com/blog</link>
	<description>A SharePoint Developer's Blog</description>
	<lastBuildDate>Fri, 23 Oct 2009 20:03:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Change the IIS Path for a SharePoint Web Application</title>
		<link>http://www.mattjimison.com/blog/2009/02/26/how-to-change-the-iis-path-for-a-sharepoint-web-application/</link>
		<comments>http://www.mattjimison.com/blog/2009/02/26/how-to-change-the-iis-path-for-a-sharepoint-web-application/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 04:26:31 +0000</pubDate>
		<dc:creator>mjimison</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.mattjimison.com/blog/?p=13</guid>
		<description><![CDATA[When creating a new web application in SharePoint, you choose the physical location of where the IIS website will be created. Once the application is born, however, there is no longer an option to change this path in Central Administration. You can very easily change it in IIS (by going to your website&#8217;s Properties -&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>When creating a new web application in SharePoint, you choose the physical location of where the IIS website will be created. Once the application is born, however, there is no longer an option to change this path in Central Administration. You can very easily change it in IIS (by going to your website&#8217;s Properties -&gt; Home Directory -&gt; Local Path), but once this is done, you will start running into trouble, as solution deployments will point to the web.config file at the old location.</p>
<p>Three quick steps need taken to successfully move the web application:</p>
<ol>
<li>Copy the current directory&#8217;s contents into your new directory</li>
<li>Make the change to the website&#8217;s local path in IIS (as described above)</li>
<li>Update the SharePoint web application to point to the new path</li>
</ol>
<p><strong>Note:</strong> If you have multiple servers in your farm, steps 1 and 2 will need made on each web server, but step 3 will only need done once.</p>
<p>The third step can be done without having to extend the site. Here are a couple options.</p>
<p><strong>Option 1: C# Console Application (Reference Microsoft.SharePoint.dll)</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.SharePoint</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.SharePoint.Administration</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> IisPath
<span style="color: #000000;">&#123;</span>
  <span style="color: #FF0000;">class</span> Program
  <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #0600FF;">try</span>
      <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">//Open the site your web application hosts</span>
        <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>SPSite site <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPSite<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;http://yoursite.com&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
          <span style="color: #008080; font-style: italic;">//Grab a reference to the site's web application's IIS Settings</span>
          <span style="color: #008080; font-style: italic;">//Change SPUrlZone if application is not in default zone</span>
          SPIisSettings iisSettings <span style="color: #008000;">=</span> site.<span style="color: #0000FF;">WebApplication</span>.<span style="color: #0000FF;">IisSettings</span><span style="color: #000000;">&#91;</span>SPUrlZone.<span style="color: #0600FF;">Default</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
          <span style="color: #008080; font-style: italic;">//Point to your new path</span>
          iisSettings.<span style="color: #0000FF;">Path</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">IO</span></span>.<span style="color: #0000FF;">DirectoryInfo</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">@&quot;D:\wss\VirtualDirectories\yoursite.com&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
          <span style="color: #008080; font-style: italic;">//Call the Update method of the web application</span>
          site.<span style="color: #0000FF;">WebApplication</span>.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
      <span style="color: #000000;">&#125;</span>
      <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
        Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        Console.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><strong>Option 2: PowerShell Script</strong></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span><span style="color: #008080;">System.Reflection.Assembly</span><span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.SharePoint&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;">#Point to the site your web application hosts to grab a reference to the web application</span>
<span style="color: #800080;">$SPSite</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> Microsoft.SharePoint.SPSite<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;http://yoursite.com&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$WebApp</span> <span style="color: pink;">=</span> <span style="color: #800080;">$SPSite</span>.WebApplication
&nbsp;
<span style="color: #008000;">#Change SPUrlZone if not in default zone</span>
<span style="color: #800080;">$IISSettings</span> <span style="color: pink;">=</span> <span style="color: #800080;">$WebApp</span>.IisSettings<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span>Microsoft.SharePoint.Administration.SPUrlZone<span style="color: #000000;">&#93;</span>::Default<span style="color: #000000;">&#93;</span>
&nbsp;
<span style="color: #008000;">#Point to your new directory</span>
<span style="color: #800080;">$IISSettings</span>.Path <span style="color: pink;">=</span> <span style="color: #800000;">&quot;D:\wss\VirtualDirectories\yoursite.com&quot;</span>
&nbsp;
<span style="color: #008000;">#Update Web Application</span>
<span style="color: #800080;">$WebApp</span>.Update<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$SPSite</span>.Dispose<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>I hope this has been helpful, and as always, thank you for reading.</p>
<p>Cheers.</p>

<div class="sociable">
<div class="sociable_tagline">
<p><strong>Share this post:</strong></p>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow" id="email"  target="_blank" href="mailto:?subject=How%20to%20Change%20the%20IIS%20Path%20for%20a%20SharePoint%20Web%20Application&amp;body=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F02%2F26%2Fhow-to-change-the-iis-path-for-a-sharepoint-web-application%2F" title="email"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="twitter"  target="_blank" href="http://twitter.com/home?status=How%20to%20Change%20the%20IIS%20Path%20for%20a%20SharePoint%20Web%20Application%20-%20http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F02%2F26%2Fhow-to-change-the-iis-path-for-a-sharepoint-web-application%2F" title="Twitter"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="facebook"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F02%2F26%2Fhow-to-change-the-iis-path-for-a-sharepoint-web-application%2F&amp;t=How%20to%20Change%20the%20IIS%20Path%20for%20a%20SharePoint%20Web%20Application" title="Facebook"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="del.icio.us"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F02%2F26%2Fhow-to-change-the-iis-path-for-a-sharepoint-web-application%2F&amp;title=How%20to%20Change%20the%20IIS%20Path%20for%20a%20SharePoint%20Web%20Application&amp;notes=When%20creating%20a%20new%20web%20application%20in%20SharePoint%2C%20you%20choose%20the%20physical%20location%20of%20where%20the%20IIS%20website%20will%20be%20created.%20Once%20the%20application%20is%20born%2C%20however%2C%20there%20is%20no%20longer%20an%20option%20to%20change%20this%20path%20in%20Central%20Administration.%20You%20can%20v" title="del.icio.us"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="digg"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F02%2F26%2Fhow-to-change-the-iis-path-for-a-sharepoint-web-application%2F&amp;title=How%20to%20Change%20the%20IIS%20Path%20for%20a%20SharePoint%20Web%20Application&amp;bodytext=When%20creating%20a%20new%20web%20application%20in%20SharePoint%2C%20you%20choose%20the%20physical%20location%20of%20where%20the%20IIS%20website%20will%20be%20created.%20Once%20the%20application%20is%20born%2C%20however%2C%20there%20is%20no%20longer%20an%20option%20to%20change%20this%20path%20in%20Central%20Administration.%20You%20can%20v" title="Digg"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="google"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F02%2F26%2Fhow-to-change-the-iis-path-for-a-sharepoint-web-application%2F&amp;title=How%20to%20Change%20the%20IIS%20Path%20for%20a%20SharePoint%20Web%20Application&amp;annotation=When%20creating%20a%20new%20web%20application%20in%20SharePoint%2C%20you%20choose%20the%20physical%20location%20of%20where%20the%20IIS%20website%20will%20be%20created.%20Once%20the%20application%20is%20born%2C%20however%2C%20there%20is%20no%20longer%20an%20option%20to%20change%20this%20path%20in%20Central%20Administration.%20You%20can%20v" title="Google Bookmarks"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow" id="stumbleupon"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.mattjimison.com%2Fblog%2F2009%2F02%2F26%2Fhow-to-change-the-iis-path-for-a-sharepoint-web-application%2F&amp;title=How%20to%20Change%20the%20IIS%20Path%20for%20a%20SharePoint%20Web%20Application" title="StumbleUpon"><img src="http://www.mattjimison.com/blog/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.mattjimison.com/blog/2009/02/26/how-to-change-the-iis-path-for-a-sharepoint-web-application/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
