MsProject技术交流群207637602

正确的修改自定义母版页方式

  网上大部分文章都是用sharepoint designer 去修改母版页,这种方式虽然能达到目的,但你的母版页存在数据库(spd设计的母版页没有保存在服务器磁盘),每次都要用spd去打开修改,不便于维护迁移,如果交接工作下一个接手人不知道这个,那就更加麻烦了。

  正确的方式是在VS中新建一个母版页,修改前端,然后在VS的sharepoint项目的Feature使用事件去修改。

  意思是每当这个Feature激活时,我们就将该SPWeb的母版页修改成我们自定义的母版页。

  代码如下:

  

if (pageNo.Equals("1"))
             {
                 page.MasterPageFile = "~masterurl/custom.master";
                 if (SPContext.Current != null)
                 {
                     SPContext.Current.Web.CustomMasterUrl = 
				"/_catalogs/masterpage/custom1.master";
                 }
             }
             else if (pageNo.Equals("2"))
             {
                 page.MasterPageFile = "~masterurl/custom.master";
                 if (SPContext.Current != null)
                 {
                     SPContext.Current.Web.CustomMasterUrl = 
				"/_catalogs/masterpage/custom2.master";
                 }
             }
             else
             {
                 page.MasterPageFile = "~masterurl/default.master";
                 if (SPContext.Current != null)
                 {
                     SPContext.Current.Web.MasterUrl = 
				"/_catalogs/masterpage/default.master";
                 }
             }

  这里需要注意的是Customer母版页和Master母版页。

  Customer母版页供用户查看,Master母版页是系统管理员进入系统页面使用的母版页。

 

  

 

posted @ 2017-05-03 11:07  鳄鱼的眼泪  阅读(978)  评论(0编辑  收藏  举报

专业MSProject,QQ411033149