About

About Me

Adiseshu Dasari
Adiseshu Dasari
AUTHOR
Adiseshu having 10 years of experience and serving as SharePoint Consultant/SharePoint Architect in, Singapore.
I have strong experience in providing solutions/ providing support / developing tools with SharePoint, .Net, SQL and BI.
I am MCPD, MCTS, MCAD certified

 

Keep in mind

All the information furnished here are my own and does not reflect the views of my employer.

The purpose of this Blog/Site is to help other people. The information included on this site is not a substitute for professional and it’s not responsible for any dispute or legal bindings.
The opinions of the loggers are their own. It’s only help out of my experience. If you feel that any copy right content is published on this site please let me know. It will be removed immediately after verification of authenticity

License: For all the generic codes, tools following license is applicable.

Copyright (c) 2012-2014 AdiCodes.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Donation:

If you are happy with tools/code used and you are keen to support adicodes.com to continue the great work, please do donate and thanks for your support

With Thanks

Adiseshu Dasari

Current Location: Singapore

4 Responses

  1. Deep - July 5, 2013

    HI Adi ,

    I need your help..
    I am using below code to download excel file from document library. while downloading requirement is savedialog box appears to save file.

    code:

    protected void lbtnDownload_Click(object sender, EventArgs e)
    {

    SPSite site = SPContext.Current.Site;
    SPWeb web = SPContext.Current.Web;
    SPList doclib = web.Lists[“Shared Documents”];
    foreach (SPListItem item in doclib.Items)
    {
    var fileName = item.File.Name;
    byte[] binFile = item.File.OpenBinary();
    System.IO.FileStream fstream = System.IO.File.Create(item.File.Name);
    // fstream.Write(binFile, 0, binFile.Length);
    //Response.ContentType = (“application/vnd.ms-excel”);
    //Response.AppendHeader(“Content-Disposition”, “attachment; filename=”+ );
    // using (var cs = new FileStream(@”c:\temp\” + fileName, FileMode.Open))
    Response.ContentType = “application/vnd.ms-excel”;
    Response.AppendHeader(“Content-Disposition”, “attachment; filename=” + fileName);

    byte[] buffer = new byte[32768];
    int read;
    while ((read = fstream.Read(binFile, 0, binFile.Length)) > 0)
    {
    Response.OutputStream.Write(binFile, 0, read);
    }
    Response.End();
    Response.Flush();

    }
    }
    Issue:

    excel file is coming balnk

  2. Adi - July 5, 2013

    Hi Deepak,

    May be this is not a page where we can post queries :)

    Any how try this code, it should work. I have tested it and it was working fine

    SPSite site = SPContext.Current.Site;
    SPWeb web = SPContext.Current.Web;
    SPList doclib = web.Lists["Shared Documents"];
    foreach (SPListItem item in doclib.Items)
     {
        var fileName = item.File.Name;
        byte[] binFile = item.File.OpenBinary();
        SPFile fileToDownload = web.GetFile(doclib.RootFolder.Url + "/" + fileName);
        Int32 bufferLength = 4096;
        Int32 readLength = bufferLength;
        Byte[] buffer = new Byte[bufferLength];
        System.IO.Stream fstream = fileToDownload.OpenBinaryStream();
                    Response.ContentType = "application/vnd.ms-excel";
                    Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
                    while (readLength == buffer.Length)
                    {
                        readLength = fstream.Read(buffer, 0, bufferLength);
                        Response.OutputStream.Write(buffer, 0, readLength);
                        if (readLength < bufferLength) break;
                    }
    
                   Response.End();
                   Response.Flush();
       }
    

    Suggestion, make it more generic to download other type of files as well with file location to save as configurable. I will try to post one generic method sometime later. Keep watching the site :)

  3. Bob Eldredge - August 7, 2013

    Adi,

    I just want you to know how much you have helped me! You are the unofficial handbook for much of what I do. Thanks so much for your willingness to share what you know!

    Bob

  4. Moses - May 7, 2015

    Hi Adi

    Do you know a quick solution on how to prevent double booking in a SharePoint Calendar (2010)?

    Regards

Leave a Reply

What is 2 + 2 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)