Developing Applications using Office Services

Discussion in 'ASP.NET' started by MinalS, May 5, 2015.

  1. MinalS

    MinalS New Member

    Joined:
    Jul 8, 2014
    Messages:
    138
    Likes Received:
    32
    Trophy Points:
    0
    The list of application services available in SharePoint are as mentioned below:
    1. Word Automation Services: It provides conversion of document files supported by Word in different formats.
    2. Excel services: It enables viewing of excel documents in the Excel web app and excel web access web parts. It provides programmatic access to the document.
    3. Access services: It provides the ability for the web databases constructed in the Access rich client to be deployed and hosted on the independent access client.
    Office Web Apps Server

    The SharePoint environment has been configured for using Office web apps server. The once developed against Office 365 SharePoint online have the configuration as the part of developer site. The user can take the advantage of WOPI in SharePoint applications, when user wants to view Excel, Word, and PowerPoint or Visio document in the web solution.

    User can view the document of the web application and saves the navigation to the file location for opening the Office client application.

    The following steps demonstrate the use of WOPI in SharePoint
    1. Execute the Visual Studio 2012 as administrator. Select the New Project option
    2. Expand the templates, select Visual C# option, and select Office/SharePoint, App nodes
    3. Add the name to the application, click ok
    4. In the specify app for SharePoint dialog, set the SharePoint site URL. It is where the app is deployed. Select the SharePoint hosted as the host for the app.
    5. In the solution explorer, expand the nodes pages, click on default.aspx file. Add the following code after the <div> tag.
      Code:
      <div>
      <h1>Add the file name saved to Shared documents</h1><br/>
      <input type="text" value="Name" id="filename" width="200px" />
      <input type="button" value="Load" id="load" width="100px" />
      <p>
          <iframe id="frame1" width="500px" height="300px" ></iframe>
      </p>
      </div>
      
    6. In the solution explorer window, expand the scripts node, remove the code and add the following code.
      Code:
      var web;
      var user;
      var context;
      var hostweburl;
      var actionEmbedParms;
      var WOPIbase;
      
      var sourcedoc1 = ‘sourcedoc=/sites/dev/Shared%20Documents/’;
      $(document).ready(function() {
          hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
          
      WOPIbase = hostweburl + "/_layouts/15/WopiFrame.apsx?" + sourcedocParm;
      actionEmbedParms = "&action = embedview&Embed=1" 
      
      context = SP.ClientContext.get_current();
      web = context.get_web();
      
      getUserName();
      
      $(‘load’).click(function() { loadIFrame (‘#fileNametxt’); } );
      
      });
      
      function getUserName()
      {
          user = web.get_currentUser();
          context.load(user);
          context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail );
          
      }
      
      function onGetUserNameSuccess()
      {
          $(‘#message’).text(‘Welcome’+user.get_title());
      }
      
      function loadIFrame(elementId)
      {
          $(‘message’).text("WOPIUrl:"+WOPIbase+$(elementid).val()+actionEmbedParms);
      }
      
      function onGetUserNameFail(sender, args)
      {
          alert(‘User name not present.Error:’+args.get_message());
      }
      
      function getQueryStringParameter(paramToRetrieve)
      {
          var params = document.URL.split("?")[1].split("&");
          var strParams = " " ;
          for(var i=0; i<params.length;i=i+1)
              var singleParam = params[i].split("=");
          if(singleParam[0] == paramToRetrieve)
              return singleParam[1];
      }
      }
      
    7. Open browser and move to the site where the application is to be deployed. Move to the Shared documents library and upload the powerpoint presentation or any document to be viewed in the app.
    8. Click on the ellipse next to the document name. On the bottom right of the viewer click the menu icon and select embed information.
    9. Locate the code containing the sourcedocParam and replace literal value with the copied code.
    10. Press F5 and execute the app. Once the page loads, in the textbox add the name of the uploaded document.
    Excel Services

    The decoupling of the Office web apps from the SharePoint server is used by the Microsoft through Hotmail, Outlook and Skydrive. Non Microsoft websites implemented using Office Web Apps servers.

    The introduction to Excel Interactive View is added in SharePoint. The service renders any HTML table on a web page within the interactive view. The script element and HTML anchor tag can be added to the page. Even if the Excel is not present in the system, the interactive icon can be clicked.

    The following code snippet shows the Excel interactive services in an auto hosted apps.
    1. Execute the Visual Studio 2012 as administrator. Select New Project option
    2. In the New Project dialog box, expand Templates, select Visual C#, click Office/SharePoint.
    3. Select App and add a name, click ok
    4. In the specify app for SharePoint dialog, set the SharePoint url used for deploying the app
    5. Choose the Autohosted option for SharePoint. Click finish
    6. In the solution explorer window, expand the pages, click Default.aspx. Add the following code in the window
      Code:
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head runat="server">
          <title>Interactive application</title>
          <script type="text/javascript" src="../Scripts/App.js"></script>
          <script type="text/javascript" src="https://r.office.microsoft.com/r/ExcelButton?v=1&kip=1" ></script>
      </head>
      <body>
          <form id="form1" runat="server">
          <div>
              <h1>SharePoint Excel Interactive View</h1>
              <div id="content"></div>
              <div>
                  <a href="#" name="ExcelButton" data-xl-tabletitle="Sales"></a>
                  <table id="showCategory">
                  </table>
              </div>
          </div>
          </form>
      </body>
      </html>
      
      
    7. In the explorer window, right click the Script folder and select Add, New Item
    8. Select the JavaScript file and save it as App.js. Click Add
    9. Add the following code in the App.js file.
      Code:
      $(document).ready(function() 
      {
          getItems();
      });
      function getItems()
      {
          $ajax({
              url:’/Pages/ProxyHTTPRequest.aspx’,
              type:’GET’
              headers: { "accept":"application/json" 
              },
              success : showItems,
              error : function () { alert (‘Fail’) ;
      }
      });
      function showItems(data)
      {
          var items = [ ] ;
          items.Push("<tr><th>Item Name</th>"+
                  "<th>Item Cost</th><tr/>");
          $.each(data.d.results, function(key, val)
          {
              items.Push(‘<tr>’+ ‘<td>’+val.Item Name+’</td>’ +
                      ‘<td>’+Item Cost+’</td>’+
          });
          $("#showItemsTable").append(items.join(‘ ‘ ) );
      }
      }
      
      
    10. In the solution explorer, right click Pages folder and select Add, New Item
    11. In Add New Item dialog, select Web form, add an appropriate name to the .aspx page and click ok
    12. Right click on the on the .aspx file, select View code. Add the following code to the Page_Load method
      Code:
      "http://services.odata.org/Service1.svc/Items?
      $select = Item Name, Item Cost&$format = json";
      string output = new WebClient().DownloadString(url);
      Response.Clear();
      
      Response.ContentType="application/json";
      Response.Write(output);
      Response.End();
      
      
    13. Next, user needs to deploy the interactive view. Click on the Excel Interactive view icon above the table.
    14. User can modify the UI as per requirements.
    15. Close the View and browser
    Access Services

    The access services consist of a resigned architecture using the new cloud app model. The Microsoft Access rich client helps user create new apps for SharePoint. The apps can be deployed on premises SharePoint or Office 365 SharePoint Online Corporate catalog for apps.

    In SharePoint 2010, the access client was used to create and publish web databases to SharePoint. The publishing generated access tables which became SharePoint lists, the web forms became .aspx pages, UI macros into JavaScript, data macros into workflows. The deployment model benefited end users for creating their point, data centric solutions.

    With Access and Services 2013, the new app cloud model provided two significant changes. SharePoint is no more the target as data source. In 2010, the data was stored in lists. Here, a SQL database is automatically generated for the solution and data is saved there. Through the new app model, all the artifacts using the access client for UI use standard web technologies. They are HTML, CSS, JavaScript, etc.

    The Access client provides tooling and Access services provides infrastructure for experts within the business domain, software vendors, software integrators for building data centric, web based solution.

    Word Automation Services

    Word Automation services allows synchronous and asynchronous, streamed file conversion. The document conversion job works efficiently on timer intervals of the service. The administrators can set the timed interval of the automation service. But it is not possible for every request. The conversion requests are submitted and processed in a real time. The stream request can be made from one file at a time. The queue manager in the architecture processes the request with higher priority.

    The PowerPoint Automation services are useful when user needs to provide the presentations in a different format. When user needs to convert the presentation from the native format to fixed format, it is useful. There is no timer job option for automation services. The files are streamed as synchronous and asynchronous pattern.

    The Microsoft.Office.Server.PowerPoint.Conversion namespace is useful for developing the solution. The PresentationRequest class uses the binary input and provides the .pptx file as output.

    The following code snippet shows the use of Automation service.
    1. Open the SharePoint Administration console, click Application management, select Manage Service applications, and confirm PowerPoint Conversion Service application and Start Proxy.
    2. Run the Visual Studio 2012 as Administrator
    3. Expand Templates, Visual C#, Windows Nodes. Select console application and add an appropriate name to it.
    4. In the solution explorer, right click project and select properties. Select the target framework as .NET framework 4. Click Build tab, set the configuration drop down list as All Configurations and close the window
    5. Right click the project, select Add Reference
    6. In the Reference manager, add System.Web namespace.
    7. In the Program.cs file, add the following code.

      Code:
      using System.IO;
      using System.Web;
      using Microsoft.SharePoint;
      using Micorosft.Office.Share.PowerPoint.Conversion;
      
      
    8. In the main method, add the following code.
      Code:
      try
      {
          string mySite="http://ServerName/SiteName";
          using (SPSite site1 = new SPSite(mySite))
          {
              using(SPWeb myweb = site1.OpenWeb())
              {
                  Console.WriteLine("Conversion started");
                  SPFolder docs = myweb.Folders[mySite+"/DocumentLibraryName"];
                  SPFile file1 = docs.Files[mysite+"/DocumentLibraryName/PresentationName.pptx"];
                  Stream FileStream1 = file1.OpenBinaryStream();
                  SPFileStream stream2 = new SPFileStream(myweb, 0x1000);
                  PdfRequest request1 = new PdfRequest( FileStream1, ".pptx", stream2);
                  IAsyncResult result = request1.BeginConvert(SPServiceContext.GetContext(site1), null, null);
                  request1.EndConvert(result);
                  SPFile PdfFile = docs.Files.Add("ConvertedPresentation.pdf", stream2, true);
                  Console.WriteLine("File Name:{0}", PdfFile.Url);
              }
          }
      }
      catch(Exception ex)
      {
          Console.WriteLine("Error Message"+ex.Message);
      }
      finally
      {
          Console.WriteLine("Conversion to pdf completed");
          Console.ReadLine();
      }
      
      
    9. Open the browser and navigate to the site. Upload the .pptx presentation file
    10. Once the file is uploaded, follow the steps mentioned below:
      1. Replace the ServerName with the URL of the SharePoint site containing the full path to the document library
      2. Replace the DocumentLibrary literal to the name of the document library
      3. Replace the PresentationName with the name of the presentation file
    11. Press F5 for code execution. The command window will show the file name after conversion
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice