以前经常混淆SharePoint里面的路径 ,因为太多了,什么相对路径,绝对路径,部署路径,经常使用的还是layouts里面的文件,因为项目部署后就放在这里。
今天将路径有关的整理出来,方便以后使用:
SPContext.Current.Web.Url:SharePoint开发
SPContext.Current.Web.ServerRelativeUrl:/
Server.MapPath(SPContext.Current.Web.ServerRelativeUrl):C:\inetpub\wwwroot\wss\VirtualDirectories\802d43787b-9f53-4d42-a97b-93a5f5ed55a3\
Server.MapPath("/"):C:\inetpub\wwwroot\wss\VirtualDirectories\802d43787b-9f53-4d42-a97b-93a5f5ed55a3\
Server.MapPath("~/"):C:\inetpub\wwwroot\wss\VirtualDirectories\802d43787b-9f53-4d42-a97b-93a5f5ed55a3\
this.AppRelativeVirtualPath:~/_layouts/15/sharepointproject1/p1.aspx
this.MapPath(this.AppRelativeVirtualPath):C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\template\layouts\sharepointproject1\p1.aspx
SPUtility.GetGenericSetupPath(string.Empty):C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\
SPUtility.GetVersionedGenericSetupPath(string.Empty, 15):C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\
SPUtility.GetVersionedGenericSetupPath(string.Empty, 14):C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\
输出上面路径的html代码如下:
SPContext.Current.Web.Url:<%=SPContext.Current.Web.Url%><br />
SPContext.Current.Web.ServerRelativeUrl:<%=SPContext.Current.Web.ServerRelativeUrl%><br />
Server.MapPath(SPContext.Current.Web.ServerRelativeUrl):<%=Server.MapPath(SPContext.Current.Web.ServerRelativeUrl) %><br />
Server.MapPath("/"):<%=Server.MapPath("/")%><br />
Server.MapPath("~/"):<%=Server.MapPath("~/")%><br />
this.AppRelativeVirtualPath:<%=this.AppRelativeVirtualPath%><br />
this.MapPath(this.AppRelativeVirtualPath):<%=this.MapPath(this.AppRelativeVirtualPath)%><br />
SPUtility.GetGenericSetupPath(string.Empty):<%=SPUtility.GetGenericSetupPath(string.Empty)%><br />
SPUtility.GetVersionedGenericSetupPath(string.Empty, 15):<%=SPUtility.GetVersionedGenericSetupPath(string.Empty, 15)%><br />
SPUtility.GetVersionedGenericSetupPath(string.Empty, 14):<%=SPUtility.GetVersionedGenericSetupPath(string.Empty, 14)%><br />
顺便说一下小技巧,在SharePoint里面,aspx文件部署后放在layouts里面,如果只是修改aspx,可以直接修改该文件,iis会实时编译输出,这样调试速度会快很多。