Is there a way to read a word document section by section with c# - c#-4.0

I have a word template which has multiple sections( tables, parragraphs, lists, etc.. ). The idea is that users fill the template and upload it to a asp.net application. I need the application to read the information section by section. So, is there a way to name the section of a word document and identify it by using c#?

I think it is much better to create a custom web page for filling fields there and constructing a Word document on the server-side using the Open XML SDK, see Welcome to the Open XML SDK 2.5 for Office for more information.
However, you may consider using bookmarks or content controls as a marker for sections.
Otherwise, you'll need to parse the uploaded document by searching for keywords presented in the template.

Related

SharePoint - Document Filtering (Tags/Metadata?)

I'm creating a SharePoint site which will be used to dynamically store and display documents on various pages, among other things. Is the following possible?
My view is to have one central Document Library which will include all files. Files with have 'tags' or 'metadata' attached to them. On pages, i will add a document library (or similar) webpart and then call only those documents with a certain tag/metadata.
For example.
Document Library ('Folder') - Contains ('Project Document.xls' and 'Training Document.ppt')
On 'index.html' i will add 'Folder' to the page, but i only want to display 'Project Document.xls' not 'Training Document.ppt'.
I'm aware that you can set up target audiences but that requires a lot of user management.
Thanks for any advice.
If I understand you correctly, this sounds like something you could accomplish using a filter. The name of the file is stored as a column. Try editing the web part on that page and edit the current view. That view will be cached for that page without changing the view across the site. If you want to be able to dynamically choose the document you display then one option is to add an HTML Form web part (which contains a text box and submit button), connect it to the doc library web part and filter the name column based on the HTML Form web part.

Flexible customization - Generating word document using C#

Problem - Generate a word document from information retrieved from database.
My solution - Create a word document template add fields/tags in places where values need to be inserted. The template will require tables and charts as well. Using document reflector that comes with open office xml sdk reflect on the document template and extract the w:document section and port it to C#. The rest of the logic revolves simply around finding the fields/tags, replacing them, etc. Very simple approach but not very flexible!
Challenge - I want the user to have the ability to customize the template or the generated document output. But this will not be possible if I embed the template logic in code.
Any other possibilities - I looked around at Templating using T4 and RazorEngine but could not find any concrete examples of how to create word documents using these two technologies.
Now what is the best approach?
I would really appreciate your inputs on what is the best and most flexible way to generate word documents using C#.
I'm actually working a project where the business users are designing word template with mail merge fields and we are populating the values using a 3rd party software package Aspose Words. http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx
The software includes a library for merging data from datatables into the mail merge fields in the word document.
I also wrote a customized word task pane add in that retrieves data views from the database and lists the fields in a drag/drop interface that mimics a crystal or sql report writing interface.
Probably would of been easier to just use crystal or sql reporting though...
It's certainly possible to generate the contents of an Office doc using T4 or Razor and then package it up. The TestScribe powertool for Visual Studio Test Manager does just that with T4. There is a thread by Sally Cavanagh in the Q&A on this page http://visualstudiogallery.msdn.microsoft.com/e79e4a0f-f670-47c2-9b8a-3b6f664bf4ae that suggests a way to look at the T4 templates that it uses, which might get you jump-started.
Here is sample to play word document template with C#
You could use a content control databinding approach.
XML Mapping Task Pane for Word 2007/2010 is an authoring tool.
To create an instance document, you just attach your XML data file.
If the resulting documents will be opened in Word, that is all that is required: Word will bind the data itself. If your consuming application is not Word, you might want to resolve the bindings yourself (eg via Open XML SDK).
Content control databinding isn't intended to support repeats and conditionals. For a way to do that, look at my OpenDoPE convention
Take a look at Templater. Disclamer: I'm the author.
Check out JODReports or Docmosis. They are Java based but some of the templating features and output options might be ideal. You can call the command line interfaces unless they also have something better to reach from C#.

Sharepoint 2010 Create PDF of document in document library

I have a document library in Sharepoint 2010. Is it possible to click on the check boxes next to a document name and convert the documents to pdf? I can't seem to find an option to do this. If not can I programmatically generate the pdf's and add them to the library.
Actually, if you have some programming skills you can create your own EventReceiver for every item added/updated to convert a word document to a PDF. By using Word Automation Services.
check this out:
http://msdn.microsoft.com/en-us/library/office/ff181518.aspx
You'll need a third party product as PDF Conversion doesn't come with SharePoint, unless you count the very basic MS-Word only conversion that is available in some editions of SharePoint 2010.
Have a look at this product, it does exactly what you want, including the checkboxes in SP2010, and can be used via workflows and web service calls as well.
Additional information as well as real world examples can be found here.
Disclaimer, I work for this vendor so it is a shameless plug. Yet it answers your question :-)
Alice,
Or you can use dynamic PDF documents, which can be integrated with Document Library as content types. Have a look at this product: it allows submitting Pdf forms using Adobe Reader (no Reader Extensions are necessary).
Disclaimer: I am using this product and happy with it. It has some limitations but nothing drastic.
Robert
MS Word provides the convert function, you can open the Word document and save as PDF format in the document library.
Also, there are some third-part tools can help you to solve this issue, such as BoostSolutions PDF Converter.

Sharepoint List to PDF report

I have a SharePoint list and I need to transform it into a document (any type) and export it to PDF. Would you have any tips on the best way to do this? I have Crystal Reports but not sure if this is the correct use case for this.
You can programatically access the document library using the object model or via web services.
If you use the object model. You can use the SPContext object to get the current site/list. From there, you can iterate through the items or, you can use a method on the SPList object to turn it into a dataset which you could then use to generate a PDF using some kind of PDF library (e.g. PDF4NET). If you go this route the best way to roll it out is by packaging it up as a feature in a solution file (.WSP) which you can deploy to your farm. In this case the code would be running in the share point environment. You can get pretty fancy with this and have something like a "Print PDF" menu option in the action menu for all lists.
On the other hand, you could also access the list remotely using the web services. In such a case you could just use this as a data provider for your reporting package.
The PDFsharepoint tool (http://www.pdfsharepoint.com) can be used to generate the PDF output. Nice thing about this tool is that you will "design" or "import" a template using WYSIWYG editor and only map the data. Without mess of coding your own PDF generator. It is not free tool though ...
I have had much success using MS-Access for creating PDF reports from SharePoint lists. You can even embed the report as a view in the list. When you select the view, it opens Access for you. Plus you can join multiple lists and even other data from within access.
Access 2007 will save a report as a PDF or you can use a PDF printer adapter such as PDFCreator.
The easiest way to export SharePoint list to pdf is, first export the list as Excel file. Then save the Excel file as Pdf document.
There is a 3rd Party product that automates this.
i-PMO's "SharePoint Data Miner" can be used to create a RS Report across any list data, then use the their SharePoint site Report Viewer and Document publisher to output the report as a PDF into a Document Library.

Complex form design in Sharepoint

I'm trying to build a form for WSS 3.0 which has the following two characteristics:
Have several sub-records in each records which contains few specific fields.
Can export to HTML or something similar which can be viewed in every browser.
I realize (unless I'm mistaken) I can achieve 1 only by using InfoPath and RepeatingSection/RepeatingTable/etc.
As for 2, I see InfoPath is only capable for exporting to MHT/PDF/XLS, none ideal for me, since the goal is to create a something that can be published to the web.
Any hints about better way to achieve this?
Correction for 2: I meant that the InfoPath form should be editable within our intranet, but exported as a read-only-web-page for our web site. So I meant "exporting" and not "publishing".
One way to do this would be to use a database as the primary data source for your forms, so that all form data is saved there. You could then build a website that queries the database for all info.
Another alternative would be to take the infopath form data (saved as an xml file) and publish it on a web server with an XML Style Sheet to define its format. You could do this via an XML control in ASP.net.
These solutions might require more elbow grease than some other solution, but I believe either would work.
Perhaps creating a custom fieldtype is a possiblity. Create a fieldtype that has some kind of collection as value.
As for 2, I see InfoPath is only
capable for exporting to MHT/PDF/XLS,
none ideal for me, since the goal is
to create a something that can be
published to the web
That's not right, InfoPath forms can be published to the web. When publishing the form to the SharePoint via the InfoPath client, you can select an option saying that this form should be editable within a browser. But beware that some form features of InfoPath are not available when you do that.
Or do you have a different understanding of "can be published to the web"? For me it means, creating a new item in the library to which the InfoPath form is attached to --> Form is opened in the browser --> user fills in the form --> user klicks the save button --> info path document is saved to the library and closed.
Just an idea:
If InfoPath (along with MOSS) is not an option, then perhaps you could mimic its behaviour through a custom edit form, if you want the data to be outputted into a SP list. I'm thinking about a custom edit form with dynamic html controls (for the sub-records), and you can achieve this by dynamically inserting objects into the DOM as your tree structure requires. Then, on form submit, an event handler on the list would parse the data submitted by the form and store it as you see fit (in an xml serialized in a custom field, for example).
If it's not going the be a custom edit form for a list, then the same functionality above can be stored in a site page with code-behind (beware of customizations) and use a hidden SP list as your data storage.
As for the exporting section, perhaps an application page linked in the ECB menu of that list would get the above mentioned xml and display it nicely.

Resources