tag:blogger.com,1999:blog-1377174316200906704.post5917225832977332485..comments2023-10-20T07:23:11.576-07:00Comments on vThink: Overwriting Files in SharePoint using Module ElementVivekhttp://www.blogger.com/profile/08310180297325901240noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-1377174316200906704.post-34281890758351092472013-08-01T16:50:40.426-07:002013-08-01T16:50:40.426-07:00Yes anonymous, we need adjust a lot of things ther...Yes anonymous, we need adjust a lot of things there, but the principal is troubleshooting the module, because some files need a different approach.<br /><br />Some files have some required properties that you need fill in module, that in code you will to get using linq-to-xml (Property).<br /><br />In code, we need to analyze too. Let's think:<br />- Pages Library: Normally requires check-out and after needs a check-in. If content approval is enabled, we need approve it.<br />- MasterPages: You cannot delete a instance that is been used, then you need check if is a masterpage before. If doesn't, you can update (overwrite) the file.<br /><br />For another types, you need check firstly if file is checked-out for another user. If yes, you need do a undo-checkout before anything.<br /><br />I recommend that you log each step to understand what is happening.<br /><br />Soon, when I finish my code here, I'll post the final version.<br /><br />See ya!Antonio Augusto A. Silveirahttps://www.blogger.com/profile/07862797598199570557noreply@blogger.comtag:blogger.com,1999:blog-1377174316200906704.post-35874534896665891402012-08-24T08:59:14.135-07:002012-08-24T08:59:14.135-07:00Actually, the last line in my comment about the fo...Actually, the last line in my comment about the foreach loop, it should be this:<br /><br />physicalPath = string.IsNullOrEmpty(file.PhysicalPath) ? Path.Combine(module.PhysicalPath, file.Name) : file.PhysicalPath;Jason Prellhttp://social.msdn.microsoft.com/profile/dream%20in%20code/noreply@blogger.comtag:blogger.com,1999:blog-1377174316200906704.post-63133394447043859942012-08-24T08:42:14.890-07:002012-08-24T08:42:14.890-07:00Visual Studio 2010 does not create a Path attribut...Visual Studio 2010 does not create a Path attribute on the Module element of the Elements.xml file when creating a new Module. The attribute is optional and could be set on the File child element instead (which is also optional). You can update the code to set PhysicalPath for module to <br /><br />PhysicalPath = (m.Attribute("Path") == null) ? string.Empty : Path.Combine(featureDir, m.Attribute("Path").Value),<br /><br />You can also add a PhysicalPath property to the Files property of Module in the code file and then set that to:<br /><br />PhysicalPath = (f.Attribute("Path") == null) ? string.Empty : Path.Combine(featureDir, f.Attribute("Path").Value),<br /><br />Then in the foreach loop for each of the files in the module, <br /><br />physicalPath = string.IsNullOrEmpty(file.PhysicalPath) ? Path.Combine(module.PhysicalPath, file.Name) : Path.Combine(file.PhysicalPath, file.Name);<br /><br />With the assumption being if there is not a Path property on the file element itself, there would be one set for the module.<br /><br />This should resolve your exception.Jason Prellhttp://social.msdn.microsoft.com/profile/dream%20in%20code/noreply@blogger.comtag:blogger.com,1999:blog-1377174316200906704.post-77294130080750484602012-08-23T12:43:31.644-07:002012-08-23T12:43:31.644-07:00Inside 'UpdateFilesInModule', when setting...Inside 'UpdateFilesInModule', when setting the module variable, you should really call FirstOrDefault() instead of First(). The way it is right now would throw an exception. FirstOrDefault would return null instead. You might want to do some additional checking inside it to see if those properties actually exist.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1377174316200906704.post-10834230760199786812012-07-26T18:34:57.072-07:002012-07-26T18:34:57.072-07:00Getting Object Reference not set error.. Any ideas...Getting Object Reference not set error.. Any ideas?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1377174316200906704.post-35274975333936956852012-07-04T18:59:35.815-07:002012-07-04T18:59:35.815-07:00Link above is broken...
Johan Leino's blog ent...Link above is broken...<br />Johan Leino's blog entry on IgnoreIfAlreadyExists is at:<br /><br />http://johanleino.wordpress.com/2009/04/22/howto-handling-file-updates-in-sharepoint/Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1377174316200906704.post-80335811669341813992012-04-06T06:20:16.925-07:002012-04-06T06:20:16.925-07:00I'm getting an error after running the activat...I'm getting an error after running the activation: The base type 'xxx' is not allowed for this page. The type is not registered as safe.<br /><br />ANyone else receive this?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1377174316200906704.post-70977540761615116112010-08-20T12:18:29.284-07:002010-08-20T12:18:29.284-07:00Just found this, exactly what I need. life saver!Just found this, exactly what I need. life saver!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1377174316200906704.post-47183177791712094612010-03-08T05:06:25.958-08:002010-03-08T05:06:25.958-08:00Thanks, the code works great!Thanks, the code works great!Himani Sharmahttps://www.blogger.com/profile/01120735018189594482noreply@blogger.comtag:blogger.com,1999:blog-1377174316200906704.post-57124075342937088802009-10-02T15:18:25.943-07:002009-10-02T15:18:25.943-07:00I was suffering from the same issue with page lay...I was suffering from the same issue with page layouts not getting updated. A coworker mentioned that he saw a post saying that page layouts with a Page tag that has the following attributes is automatically considered customized as soon as it is installed:<br /><br /> meta:progid="SharePoint.WebPartPage.Document" meta:webpartpageexpansion="full"<br /><br />I thought there was no way it would work and I'd be writing code to update the page layouts, but when they were removed, at least based on my initial testing, they actually update now. <br /> <br />Now if you already have a bunch of pages using the page layout you want to change and it was installed with those tags still in them, it seems like it might be a catch22 (there's no way to get the updated page layout into those sites since those pages are considered customized, in which case it might take code to unwind it--but more as a one time adminstrative thing). That's just a theory though. I'm not sure if there are any bad side effects to removing those tags, but I'll be on the watch for them.Clark Updikehttps://www.blogger.com/profile/14749271058929226616noreply@blogger.comtag:blogger.com,1999:blog-1377174316200906704.post-6463429693539364712009-09-03T08:04:53.507-07:002009-09-03T08:04:53.507-07:00Another approach to this would be a feature receiv...Another approach to this would be a feature receiver that simply deletes the file in question before using an standard modules feature to upload your new copy. <br /><br />You could use Activation Depenencies to ensure that the orginal file is deleted before the module feature uploads the new one.<br /><br />This is much simpler from a code perspective and is just this:<br /><br />using (SPSite site = new SPSite("http://yoursiteurl"))<br />{<br />using (SPWeb web = site.RootWeb) //or find your web by some other method if it is not the root web<br />{<br />web.GetFile(web.Url +"/the full path to your file").Delete();<br />}<br />}<br /><br />Not saying this is a 'better' solution, the one outlined here is very good and comprehensive, just an alternative is all.<br /><br />RegardsMartin Kearnhttp://blogs.msdn.com/uksharepoint/default.aspxnoreply@blogger.comtag:blogger.com,1999:blog-1377174316200906704.post-43800348027304988492009-08-09T01:33:05.617-07:002009-08-09T01:33:05.617-07:00Thanks Christoph, I am glad it helped you.
I'l...Thanks Christoph, I am glad it helped you.<br />I'll post the project soon.Vivekhttps://www.blogger.com/profile/08310180297325901240noreply@blogger.comtag:blogger.com,1999:blog-1377174316200906704.post-6533866724758405832009-08-06T08:42:47.707-07:002009-08-06T08:42:47.707-07:00Awesome...had the problem with Page Layouts deploy...Awesome...had the problem with Page Layouts deployed by features. <br />Would be great you post the Project as a zip, not only the source code. Had some trouble with namespaces. <br />Thanks, saved me!Christophhttps://www.blogger.com/profile/06385035900618657896noreply@blogger.comtag:blogger.com,1999:blog-1377174316200906704.post-52698032723158845272009-07-17T01:56:57.524-07:002009-07-17T01:56:57.524-07:00Great that you found my blogpost as a good example...Great that you found my blogpost as a good example and great that you have extended it with some modifications, I´ll add them to my personal code lib :-). / Johan - not John ;-)Johan Leinohttp://johanleino.spaces.live.comnoreply@blogger.com