TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sunil mule
NA
22
2.2k
Download code not working
Dec 17 2016 1:53 PM
Hi ,
I have share point visual web part and it contain a button for download some files from share point point lib. but when i did below code it runs smoothly but nothing happens no error no file download i don't know whats wrong with the code can some one please help me to sort it out. below is code sample
string sourceSiteURL=SPContext.Current.Web.Url;
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer = true;
byte[] obj = null;
using (SPSite oSite = new SPSite(sourceSiteURL))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
oWeb.AllowUnsafeUpdates = true;
SPFolder myLibrary = oWeb.Folders["DocumentSent"];
SPList oList = oWeb.Lists[sourceDocumentLibrary];
SPListItemCollection oListItems = oList.Items;
string line = string.Empty;
try
{
foreach (SPFile oItem in myLibrary.Files)
{
if (oItem.Url.Contains(applicationFileName + ".pdf"))
{
response.AddHeader("Content-Disposition", "attachment;filename=\"" + applicationFileName + ".pdf" + "\"");
response.ContentType = "application/pdf";
StreamReader reader = new StreamReader(oItem.OpenBinaryStream());
SPFile tempFile = oWeb.GetFile(oItem.Url);
obj = (byte[])tempFile.OpenBinary();
if (response.IsClientConnected)
{
response.BinaryWrite(obj);
}
response.BufferOutput = true;
response.Flush();
response.Close();
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
//response.End();
}
}
}
Thanks
Reply
Answers (
1
)
Error occurred in deployment step 'Activate Feature':
SharePoint 2013 online word to Pdf Conversion using CSOM