1

I have a web part which shows the list of documents which are stored in the document library. I want to open the document in respective client application of client machine programmatically.

Scenario for example: There are three files displayed in the web part, among them one is word, other is excel and the third one is power point file. If user clicks on any of file it should be opened in respective client machine's application.

How to do that? Please provide any sample code or reference links.

1

What are you seeing now? By default SharePoint will open office documents in their clients as long as:

  1. Client Integration is enabled
  2. Open in Client is configured for libraries (this is default behavior)
  3. There are combinations of IE/Office that can be required on the client side due to ActiveX requirements. IF you are using IE10 and Office 2013, you should not need anything else, if you are using an older browser than there is an ActiveX control that gets installed with office (if you installed the SP Shared components).

Outside of this, the browser will just attempt to download the object, and if you have the file association configured on the client, then the client - and not SharePoint determines how it will be opened.

0

You need to do something like this..

FileInformation fileinfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext,file.ServerRelativeUrl);
byte[] bytesarr = ReadFully(fileinfo.Stream);

public byte[] ReadFully(Stream input)
    {
        byte[] buffer = new byte[16 * 1024];
        using (MemoryStream ms = new MemoryStream())
        {
            int read;
            while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
            {
                ms.Write(buffer, 0, read);
            }
            return ms.ToArray();
        }
    }

Now you need to use bytesarr object of byte array into save file dialog box, Hope it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.