Introduction

This blog is mainly focused on SharePoint
I will use this to store and share all the tips and tricks about SharePoint and the related products
List of all posts

Copy of SPItem with rigths and modification of author and creation date


Copy of SPItem with rigths and modification of author and creation date

Partial code
        private void tzCopyDoc() {
            string destUrl = _destList.ParentWeb.Url + "/" + _destList.RootFolder.Url + "/" + _sourceItem.File.Name;
            byte[] binFile = _sourceItem.File.OpenBinary();

            SPUser oUserAuthor = _author;
            SPUser oUserModified = _sourceItem.File.ModifiedBy;
            System.DateTime dtCreated = System.DateTime.Now ;
            System.DateTime dtModified = System.DateTime.Now;

            SPFile oFileNew = _destList.RootFolder.Files.Add(destUrl, binFile, oUserAuthor, oUserModified, dtCreated, dtModified);
            SPListItem oListItem = oFileNew.Item;
            oListItem["Created"] = dtCreated;
            oListItem["Modified"] = dtModified;
            oListItem.Update();

            SPRoleAssignmentCollection roles = _sourceItem.RoleAssignments;
            oListItem.BreakRoleInheritance(true);
            while (oListItem.RoleAssignments.Count > 0) { oListItem.RoleAssignments.Remove(0); }
            foreach (SPRoleAssignment role in roles) {
                oListItem.RoleAssignments.Add(role);
            }
            
            //copy file attributes
            SPFile myFile = _destList.ParentWeb.GetFile(destUrl);

            //copy any  field values that match in both lists
            CopyFieldValues(this._sourceItem, myFile.Item);
            myFile.Item.SystemUpdate();
        }




Powershell and SPSolutions : Install, Update, Uninstall


Powershell and SPSolutions

Action script
Install
Add-SPSolution c:\installtzsol\TzToolsFeature.wsp
Install-SPSolution –Identity TzToolsFeature.wsp  -GACDeployment
Update
Update-SPSolution –Identity TzToolsFeature.wsp –LiteralPath c:\installtzsol\TzToolsFeature.wsp –GACDeployment
UnInstall
Uninstall-SPSolution –Identity TzToolsFeature.wsp

by Category