Showing posts with label Docuement library. Show all posts
Showing posts with label Docuement library. Show all posts

Friday, December 2, 2016

Delete all files & folders from SharePoint library

Add-PSSnapin Microsoft.SharePoint.PowerShell

# Replace siteurl with actual web url
$web = Get-SPWeb -Identity "siteurl"
# Replace docurl with document library url
$list = $web.GetList("docurl")

function DeleteFiles {
    param($folderUrl)
    $folder = $web.GetFolder($folderUrl)
    foreach ($file in $folder.Files) {
        # Delete file by deleting parent SPListItem
        Write-Host("DELETED FILE: " + $file.name)
        $list.Items.DeleteItemById($file.Item.Id)
    }
}

# Delete root files
DeleteFiles($list.RootFolder.Url)

# Delete files in folders
foreach ($folder in $list.Folders) {
    DeleteFiles($folder.Url)
}

# Delete folders
foreach ($folder in $list.Folders) {
    try {
        Write-Host("DELETED FOLDER: " + $folder.name)
        $list.Folders.DeleteItemById($folder.ID)
    }
    catch {
        # Deletion of parent folder already deleted this folder
    }
}

Monday, October 24, 2016

Where attachments are being stored in sharepoint

Like the documents in a document library, attachments are stored in Blob form in the content database

You can use Sharepoint Designer to access your Sharepoint Site, there are the Document Librarys and the documents you upload.

Thursday, June 9, 2016

How can you move a document with its version history to a new library?

Tools:

 Lars Fastrup has created a tool that does just what you want: CopyMove for SharePoint
It also has a web service API.

2 document libraries
Both contain multiple documents
The documents have multiple versions
using objects like SPExport and SPImport

the copy, move actions of the content site and structure (sitemanagement.aspx) are performed using this API.

Current Limitations:

Document libraries should be in the same site.
Only default document library view is supported:
All views should have title.
All views should have summary toolbar.
All views should have the type and the name columns.
Only files with title can be moved.
You can’t drag folders or drop into folders.
Current Features:

Copy Operation has been added.
Folders are supported now.
Planned Features:

Delete Document by drag it to Recycle Bin.

Support Multiple Item Selection.

How to override a checked out document?

 Hhigh enough permission level you can select the document, go over the ribbon to files and click "Discard Check Out"


Saturday, April 9, 2016

Freeze header in SharePoint List 2013

In this below script, Freeze header in SharePoint List 2013

Freeze header in SharePoint List
The stickyHeaders widget as part of the Sharepoint List .

_spBodyOnLoadFunctionNames.push("stickyHeaders");

function stickyHeaders() {//-----------------------------------------------------------------------------------------------------------------------------------------------
//Class
function List () {
this.list               = "";
this.webpart            = "";
this.sticky             = "";
this.header             = "";
this.dphm               = "";
this.s4                 = "";
this.contentBox = "";
this.top_old            = 0;
this.top_new            = 0;
this.bottom_old         = 0;
this.bottom_new         = 0;
this.wpBottomBorder_old = 0;
this.wpBottomBorder_new = 0;
this.wpTopBorder_old    = 0;
this.wpTopBorder_new    = 0;
this.wpScrollPos_old    = 0;
this.wpScrollPos_new    = 0;
this.prevHeight         = 0;
this.permsWithAnon      = 0;
this.fixedHeight        = 0;
this.fixedWidth         = 0;
this.widthChange        = true;
this.setWidth = function() {
if(this.widthChange){
if(this.fixedWidth) {
//TODO
//$(this.sticky).css("overflow-x","hidden")
//$(this.sticky).width($(this.sticky).closest("[id^=WebPartWPQ][style*=width]").width() - 18).children().each(function (j) {
// $(this.header).css("min-width",$(this.header).children('*:nth-child(' + (j+1) + ')').width())
//});
} else {
this.sticky.width(this.header.width());
for(var k=0, childrenLength = this.sticky.children().length; k<childrenLength; k++){
this.sticky.children().eq(k).width( this.header.children().eq(k).width() ).css("max-width","");
}
}
this.widthChange = false;
}
};
this.setLeftOffset = function() {
var parent = this.webpart.length != 0 ? this.webpart : this.dphm;
this.sticky.css("left",(parent.offset().left + parseInt(parent.css("padding-left")) - 2) + "px");
};
this.setTopPosition = function() {
if( !this.fixedHeight ){
this.sticky.css("top", (this.s4.offset().top + 2));
} else {
this.sticky.css("top",this.webpart.offset().top + "px")
if(this.sticky.attr('data-hidden', false) && this.sticky.offset().top < (this.s4.offset().top + 2)){
this.sticky.css("top", (this.s4.offset().top + 2));
}
}
};
this.update = function(eventType) {
if(this.sticky.attr('data-hidden', false)){
this.setLeftOffset();
this.setTopPosition();
}
if(eventType == "scrollList"){
this.wpScrollPos_old = this.wpScrollPos_new
this.wpScrollPos_new = this.webpart.scrollTop()

if(this.wpScrollPos_old <= this.prevHeight && this.wpScrollPos_new >= this.prevHeight ){
this.contentBox = this.list.find(".ms-core-menu-box")
this.contentBox.appendTo(this.sticky.find("th").eq(this.contentBox.closest("th").index()))
this.setWidth()
this.sticky.fadeIn().addClass("typeA");

} else if(this.wpScrollPos_old >= this.prevHeight && this.wpScrollPos_new <= this.prevHeight ) {
if(!this.sticky.hasClass("typeB")){
this.sticky.fadeOut().removeClass("typeA");
} else {
this.contentBox = this.sticky.find(".ms-core-menu-box")
this.contentBox.appendTo(this.header.find("th").eq(this.contentBox.closest("th").index())).css({"top":"auto","left":"auto"})
this.sticky.removeClass("typeA")
}
}
} else {
this.top_old = this.top_new;
this.top_new = this.header.offset().top - this.s4.offset().top;

this.bottom_old = this.bottom_new;
this.bottom_new = this.top_new - 30 + this.list.height();

if(this.fixedHeight) {
this.wpTopBorder_old = this.wpTopBorder_new;
this.wpTopBorder_new = this.webpart.parent().offset().top - this.s4.offset().top;
this.wpBottomBorder_old = this.wpBottomBorder_new
this.wpBottomBorder_new = this.webpart.parent().offset().top + parseInt(this.webpart.css("height")) - this.s4.offset().top


//fix for the permission this.when anonymous access is activated
this.bottom_new = this.permsWithAnon ? this.top_new - 30 + this.dphm.height() : this.bottom_new

this.bottom_old         = !this.bottom_old         ? this.bottom_new         : this.bottom_old;
this.top_old            = !this.top_old            ? this.top_new            : this.top_old;
this.wpBottomBorder_old = !this.wpBottomBorder_old ? this.wpBottomBorder_new : this.wpBottomBorder_old;
this.wpTopBorder_old    = !this.wpTopBorder_old    ? this.wpTopBorder_new    : this.wpTopBorder_old;

if (this.top_old >= 0 && this.top_new <= 0 || this.bottom_old <= 0 && this.bottom_new >= 0 || this.fixedHeight && ( this.wpBottomBorder_old <= 0 && this.wpBottomBorder_new >= 0 || this.wpTopBorder_old >= 0 && this.wpTopBorder_new <= 0 ) || ( this.top_old == this.top_new && this.bottom_old == this.bottom_new && this.top_old < 0 && this.bottom_old > 0 )) {
this.contentBox = this.list.find(".ms-core-menu-box")
if(this.contentBox){
this.contentBox.appendTo(this.sticky.find("th").eq(this.contentBox.closest("th").index()))
}
this.setWidth()
this.sticky.fadeIn().addClass("typeB")

} else if (this.top_old <= 0 && this.top_new >= 0 || this.bottom_old >= 0 && this.bottom_new <= 0 || this.fixedHeight && ( this.wpBottomBorder_old >= 0 && this.wpBottomBorder_new <= 0 || this.wpTopBorder_old <= 0 && this.wpTopBorder_new >= 0 )){
this.contentBox = this.sticky.find(".ms-core-menu-box")
this.contentBox.appendTo(this.header.find("th").eq(this.contentBox.closest("th").index())).css({"top":"auto","left":"auto"})
if(!this.sticky.hasClass("typeA")){
this.sticky.fadeOut().removeClass("typeB");

if(this.sticky.hasClass("typeA")){
if(this.wpBottomBorder_new <= 0){
this.sticky.removeClass("typeB").fadeOut();
} else {
this.sticky.removeClass("typeB")
}
}
}
}
}
}

(function (){
var wpq = $("#DeltaPlaceHolderMain [id^=MSOZoneCell_WebPartWPQ]:visible");
if (wpq.length === 1) {
function ShowContextRibbonSections() {
SP.Ribbon.WebPartComponent.registerWithPageManager({editable: true, isEditMode: false, allowWebPartAdder: false});
var wpcomp = SP.Ribbon.WebPartComponent.get_instance();
if (wpcomp) {
wpcomp.selectWebPart(document.getElementById(wpq.attr('id')), true);
}
}

ExecuteOrDelayUntilScriptLoaded(ShowContextRibbonSections, "sp.ribbon.js");
var DeselectAllWPItems_old = DeselectAllWPItems;
DeselectAllWPItems = function () {
DeselectAllWPItems_old();
setTimeout(function () { ShowContextRibbonSections(); }, 25);
};
}

var RibbonContainer = $("#RibbonContainer")
var ribbonHeight = RibbonContainer.height();
g_workspaceResizedHandlers.push(function () {
setTimeout(function () {
var newRibbonHeight = RibbonContainer.height();
if (ribbonHeight !== newRibbonHeight) {
findListsOnPage(false);
ribbonHeight = newRibbonHeight;
}
}, 500);
});

if (jQuery.inArray("spgantt.js", g_spPreFetchKeys) > -1) {
SP.SOD.executeOrDelayUntilScriptLoaded(function () {
setTimeout(function () { findListsOnPage(false); }, 500);
}, "spgantt.js");
} else {
findListsOnPage(false);
}

$(window).bind('hashchange.stickyHeaders', function () {
findListsOnPage(true);
});
})()

function findListsOnPage(hashchange) {
window['listContainer'] = {"lists":[]}

var quickEdit = false;

$("tr:has(>th[class^='ms-vh']):not(.sticky):visible, .ms-listviewgrid").closest("table").each(function(){
if($(this).find("tbody > tr").length > 1){
listContainer.lists.push(new List());
listContainer.lists[listContainer.lists.length - 1].list = $(this);
if($(this).hasClass('.ms-listviewgrid')){
quickEdit = true;
}
}
})

if (quickEdit) {
SP.GanttControl.WaitForGanttCreation(function () {
setTimeout(function () {
initializeStickyHeaders(listContainer,hashchange);
}, 1000);
return;
});
} else {
setTimeout(function(){initializeStickyHeaders(listContainer,hashchange);},0)

}
}

function initializeStickyHeaders(container,hashchange) {
$(window).unbind('resize.stickyHeaders');
$(window).bind ('resize.stickyHeaders', function () { $(container.lists).each(function(){this.update("resize")}) });

$('#s4-workspace').unbind('scroll.stickyHeaders');
$('#s4-workspace').bind('scroll.stickyHeaders', function () { $(container.lists).each(function(){this.update("scroll")}) });

$(container.lists).each(function(){
this.webpart        = this.list.closest("[id^=WebPartWPQ]")
this.header         = this.list.find("tr:has(>th):not(.sticky):visible")
this.dphm           = this.list.closest("#DeltaPlaceHolderMain");
this.s4             = $("#s4-workspace")
this.permsWithAnon  = this.list.closest("div[id$='rptrAnony__div']").length;
this.fixedHeight    = this.list.closest("[id^=WebPartWPQ][style*=height]").length;
this.fixedWidth     = this.list.closest("[id^=WebPartWPQ][style*=width]").length;

var prevElem = this.header.closest("table").prevAll()
for(var i=0, prevElemLength = prevElem.length;i<prevElemLength;i++){
this.prevHeight = this.prevHeight + $(prevElem[i]).outerHeight()
}

if(this.fixedHeight || this.fixedWidth){
this.webpart.bind("scroll",{elem:this}, function(event){
event.data.elem.update("scrollList")
})
}

if (!this.webpart.find(".sticky").length) {
this.list.before('<div class="sticky-anchor"><span></span></div>');
this.sticky = this.header.clone(true, true).addClass("sticky").attr('style', "position: fixed; border: 1px solid grey; background-color: white; box-shadow: 0 0 6px -2px black; display: none;").insertAfter(this.list);
this.sticky.find("#users_imn_header").attr("src", "/_layouts/15/images/imnhdr.gif")
this.sticky.find(".ms-selectall-span img").on("click",{header:this.header},function (event) {
var span = event.data.header.find(".ms-selectall-span")
span[0].checked = span[0].checked ? false : true;
ToggleAllItems2(span[0], span.attr("id").substr(17), span[0].checked)
});
} else {
if(hashchange){
this.sticky = this.list.closest("div").find(".sticky");
/*
var childrenLength = $(this.header).children().length
for(k=0; k<childrenLength; k++){
if(!this.header.children().eq(k).find(".ms-filter-iconouter").attr('data-hidden')){
this.header.children().eq(k).find(".ms-filter-iconouter").css("display","inline-block")
} else {
this.header.children().eq(k).find(".ms-filter-iconouter").css("display","none")
}
if(!this.header.children().eq(k).find(".ms-sortarrowdown-iconouter").attr('data-hidden')){
this.header.children().eq(k).find(".ms-sortarrowdown-iconouter").css("display","inline-block")
} else {
this.header.children().eq(k).find(".ms-sortarrowdown-iconouter").css("display","none")
}
}
*/
} else {
this.sticky = this.list.closest("div").find(".sticky");
}
}

//update stickies when grouped views are expanded or collapsed
this.list.children("tbody[id^='titl']").find(".ms-gb a").bind('click.stickyHeaders',{elem:this},function (event) {
var elem = event.data.elem
elem.widthChange = true
interval = setInterval(function(){
if($("#tbod" + $(event.target).closest("tbody").attr("id").substr(4) + "_").attr("isloaded") == "true"){
elem.update("expandCollapse");
clearInterval(interval);
}  
},1)
});
});
$(container.lists).each(function(){this.update("standard")})
}

(function () {
$("<div/>", {html: '&shy;<style>.sticky .ms-core-menu-box {top: auto !important; left: auto !important;}</style>'}).appendTo("body");
})();
}

Tuesday, March 29, 2016

How to change SharePoint list field color using jquery code base on value?

In this below script, hange SharePoint list field color using jquery code

change SharePoint list field color
 $("table.ms-listviewtable > tbody > tr > td:nth-child(columnNumber) > div").filter(function() {
        ( parseInt( $(this).text() ) > 59 ) ? $(this).css("background-color", "#00FF66") : null  
    });

How to open a calendar item in a modal dialog?

In this below script, open a calendar item in a modal dialog

open a calendar item in a modal dialog In SharePoint
function openDialog(pageUrl) {
  var options = {
      title : "calender",
      width : 500,
      height : 400,
      url : pageUrl
  };

  SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}

$('.ms-acal-month').ready(function () {
   setTimeout(function() {
       $('a[href*="DispForm.aspx"]').each(function() {
           $(this).attr('onclick', 'openDialog("' +  $(this).attr('href') + '")');
           $(this).attr('href','javascript:void(0)');
       });
   }, 1000);
});

Monday, March 7, 2016

File size limit and/or update count limit List and Library



Maximum file size limit is 2 GB

Default values are:

For SharePoint 2013: default max file size is 250 MB
For SharePoint 2007/2010: default max file size is 50 MB











https://technet.microsoft.com/en-us/library/cc262787(v=office.14).aspx#ListLibrary

Wednesday, March 2, 2016

How to Insert New Item Into SharePoint List Programmatically

using (SPSite spSite = new SPSite(strSiteUrl, token))
{
spSite.AllowUnsafeUpdates = true;
using (SPWeb spWeb = spSite.OpenWeb())
{


SPList spList = spWeb.Lists["Enquiry"];

SPListItem spListItem = spList.Items.Add();

spListItem["Title"] = "Peak";
spListItem["Location"] = "India";


spWeb.AllowUnsafeUpdates = true;
 spListItem.Update();
}

}

Thursday, February 18, 2016

Drag & Drop in SharePoint Document libraries in SharePoint 2010

Please follow the below url step
In that article ,Have script file we have to add content editor webpart.

Some restriction will be restrictions. 


http://dandd.codeplex.com/

How to move a document with version history to a new library?


  •  Drag & Drop a file in Explorer View from one document library to another,
  •  Both libraries need to have versioning enabled.
  • Retains the versions if you MOVE the files. It does not do so when you perform a COPY

Tuesday, January 19, 2016

How to Lookup Column Value and XSL SharePoint Default forms?

Please add attribute  this

disable-output-escaping="yes"


<xsl:value-of select="@Designation" />

Try  like this:


<xsl:value-of select="@Designation" disable-output-escaping="yes" />

How to add edit link in sharepoint 2013 list column


Do below steps
  • Open the AllItems.aspx page view for the specific list.
  • Search for the <ViewFields> tag
  • List item linkToItem="TRUE" to whichever column you want the link:

<ViewFields><br/>
    <FieldRef Name="Attachments"/><br/>
    <FieldRef Name="LinkTitle"/><br/>
    <FieldRef Name="Name" linkToItem="TRUE"/><br/>
    <FieldRef Name="Designation"/><br/>
    <FieldRef Name="Manager"/><br/>
</ViewFields><br/>

Monday, December 21, 2015

Rename file in a document library folder

if (properties.BeforeUrl != properties.AfterUrl)
{
string[] onp = properties.BeforeUrl.Split('/');
string ofn= onp[onp.Length - 1]; // get the old file name
string name= Path.GetFileNameWithoutExtension(ofn);
string[] nnp = properties.AfterUrl.Split('/');
string nfn = nnp[nnp.Length - 1]; //get the new file name

string furl = doculibrUrl + "/Shared Folder/" + name+ ".tiff";
SPFile file = web.GetFile(fURL);
if (file.Exists)
{
    file.Item["Name"] = nfn;
    file.Properties["Title"] = nfn;
    file.Item.Update();                               
}
return;
}

Thursday, February 12, 2015

Unable to save site as template + unexpected error.

when we document library [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration")
$docSize = 5000000000
$webservice = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$webservice.MaxTemplateDocumentSize = $docSize
$webservice.Update()