Here I wil talk about how
to download sharepoint file (image/Document/Video) on button click, SharePoint
provides you inbuilt solution using STSNavigate function which helps to
navigate to system page download.aspx and download.aspx contains code to
download file
In above line of code STSNavigate will do magic of giving user save as option of specified file URL, also here we are using system page download.aspx
2. If using client object model
})
1. If using server side
code
downloadButton.OnClientClick
= "STSNavigate('" + SPContext.Current.Web.Url +
"/_layouts/15/download.aspx?SourceUrl=" + fileURL + "' ); return
false;";
In above line of code STSNavigate will do magic of giving user save as option of specified file URL, also here we are using system page download.aspx
2. If using client object model
if below code the only thing you need to do is to form
fileURL.
$(‘#<%=btnDownload.ClientID%>’).click(function
(e) {
STSNavigate(‘<%= SPContext.Current.Web.Url %>/_layouts/15/download.aspx?SourceUrl=’ + fileURL);
return false;STSNavigate(‘<%= SPContext.Current.Web.Url %>/_layouts/15/download.aspx?SourceUrl=’ + fileURL);
})
good... you saved my time
ReplyDelete