Retrieve all items in a list by caml query then write it to a word file page by page

Dears,
Greetings
I have some code which will retrieve all items of a list with caml query.
Now i want to generate a word file with all these retrieved data. I am using foreach here to get all the items in a SPListItemCollection. Now my question is how i can write all the retrieved items inside the word file?
see the below code which is writing only the last row item of the SPListItemCollection inside word file. I want to write all the retrieved rows inside this word file.
SPQuery qry = new SPQuery();
qry.Query = "<Where><Eq><FieldRef Name='Department' /><Value Type='Text'>HR DEPARTMENT</Value></Eq></Where>";
SPListItemCollection listItems = KPILIst.GetItems(qry);
foreach (SPListItem item in listItems)
lblBadgeNo.Text = item["Badge No"].ToString();
lblName.Text = item["Name"].ToString();
lblPosition.Text = item["Position"].ToString();
lblDept.Text = item["Department"].ToString();
lblHireDate.Text = item["Hire Date"].ToString();
lblGrade.Text = item["Grade"].ToString();
lblCurStatus.Text = item["Status"].ToString();
string FinalOut = "";
FinalOut = "<table cellpadding=0 cellspacing=0><tr><td style='height:30px;'></td></tr><tr><td style='height:22px;'></td></tr>";
FinalOut = FinalOut + "<tr><td style='text-align:justify;font-size:22px;'>" + lblBadgeNo.Text + "</td></tr>";
FinalOut = FinalOut + "<tr><td style='text-align:justify;font-size:22px;'>" + lblName.Text + "</td></tr>";
FinalOut = FinalOut + "<tr><td style='text-align:justify;font-size:22px;'>" + lblDept.Text + "</td></tr>";
FinalOut = FinalOut + "<tr><td style='text-align:justify;font-size:22px;'>" + lblHireDate.Text + "</td></tr>";
FinalOut = FinalOut + "</table>";
System.Text.StringBuilder strBody = new System.Text.StringBuilder("");
strBody.Append("<html " + "xmlns:o='urn:schemas-microsoft-com:office:office' " + "xmlns:w='urn:schemas-microsoft-com:office:word'" + "xmlns='http://www.w3.org/TR/REC-html40'>" + "<head><title>EPCCO : HR Comapny Letter</title>");
strBody.Append("<!--[if gte mso 9]>" + "<xml>" + "<w:WordDocument>" + "<w:View>Print</w:View>" + "<w:Zoom>90</w:Zoom>" + "<w:DoNotOptimizeForBrowser/>" + "</w:WordDocument>" + "</xml>" + "<![endif]-->");
strBody.Append("<style>" + "<!-- /* Style Definitions */" + "@page Section1" + " {size:8.5in 11.0in; " + " margin:1.0in 1.25in 1.0in 1.25in ; " + " mso-header-margin:.5in; " + " mso-footer-margin:.5in; mso-paper-source:0;}" + " div.Section1" + " {page:Section1;}" + "-->" + "</style></head>");
strBody.Append("<body dir=rtl lang=EN-US style='tab-interval:.15in'>" + "<div class=Section1>" + FinalOut.ToString() + "</div></body></html>");
Response.AppendHeader("Content-Type", "application/msword");
Response.AppendHeader("Content-disposition", "attachment; filename=Eval_" + lblBadgeNo.Text + ".doc");
Response.Write(strBody);
Regards
Shaji
I am new to SharePoint

Hello,
you can try with OpenXML SDK to create word file. I found one link for your reference:
http://sharepointplace.blogspot.in/2009/12/programmatically-creating-word.html
Another way is , use Microsoft Word Object Library.
http://social.msdn.microsoft.com/Forums/vstudio/en-US/5b82c0b5-ecaf-40f2-a68a-c7c17c85414f/create-word-documents-by-c?forum=csharpgeneral
Hope it could help
Hemendra:Yesterday is just a memory,Tomorrow we may never see
Please remember to mark the replies as answers if they help and unmark them if they provide no help

Similar Messages

  • How to check all items are not null in CAML Query?

    HI All,
    In a CAML Query, i got three items. In all three items, a particular column(Closure Date) should not be null. How to check in all three items, where 'Closure date' is not null?
    Thanks in advance!

    Hi,
    Try this:
    "<Where><IsNull><FieldRef Name='Closure Date' /></IsNull></Where>"
    Hope it hepls!
    Thanks,
    Avni Bhatt
    If this helped you resolve your issue, please mark it Answered

  • How to sum all items in a list in applescript?

    Hey guys,
    I wanted to sum all items of a list full of numbers and divide the number by the count all items of a list, is there a easy way to do this?
    Thank you so much in advance

    You didn't say which is the source of the list.
    Assuming that the list isn't extractyed from a Numbers table Niel's answer is OK.
    If you installed the free OSAX Satimage
    http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html
    you may study its arrays functions.
    For this tool, a list is a simple array so you may apply the function statsrecord
    Yvan KOENIG (VALLAURIS, France) samedi 4 février 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My Box account  is : http://www.box.com/s/00qnssoyeq2xvc22ra4k

  • Programmatically select all items in a list

    Hi, I've been looking through the online docs trying to find
    a way to programmatically select all items in a list. I have a
    checkbox that when checked should select all items in a list. I
    found a method to clear all selections but not one to select all.
    Did I just miss it? Thanks!

    I don't know of any built-in functions to select all list
    items, but here is an example function to select all items in a
    list:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    xmlns="*" layout="absolute">
    <mx:Script>
    <![CDATA[
    [Bindable] private var people_xml:XML =
    <people>
    <person>Jen</person>
    <person>Brian</person>
    <person>Scot</person>
    </people>;
    private function select_all():void {
    var indices:Array = new Array();
    for (var i:uint = 0; i<people_xml.children().length();
    i++) {
    indices.push(i);
    peopleList.selectedIndices = indices;
    ]]>
    </mx:Script>
    <mx:Button x="125" y="10" label="Select All"
    click="select_all()"/>
    <mx:List x="10" y="10" allowMultipleSelection="true"
    dataProvider="{people_xml.person}" id="peopleList"
    labelField="person" width="107"></mx:List>
    </mx:Application>
    Vygo

  • Failed to retrieve all the results. Try running the query or stored procedure again

    I have a Product table in Azure SQL Database. I can't open data in Product table. I got an error message like this.."Failed to retrieve all the results. Try running the query or stored procedure again". In my Database
    all tables showing their data expect Product table. Please let me know why only Product table showing error message. Thanks in Advance.

    Hi,
    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience
    As this requires an expert advice, I suggest you to open a support case and our experts would be able to assist you further.
    http://support2.microsoft.com/common/international.aspx?RDPATH=%2fdefault.aspx%3fid%3dfh%253ben-us%253bofferprophone
    Girish Prajwal

  • Retrieving all options in a list box

    I am very new to JSP, though I've done a little with ASP before. I have a page in which users can add and/or delete text concerning levels of discussion. They can also move them up and down to place them between two other levels by using one of two buttons. When the user is done with the form, I then need to update the database table which these levels are in. This is the part I am having trouble figuring out. How do I retrieve all of the items in the list (select with multiple lines) in the order they placed them? Is it just a simple request.getParameter or would this just give me the item that was selected last?
    Chris

    I think you'll have to create a "hidden" form variable
    (like <input type="hidden" id="allList" />)
    and upon form submission, do some javascript to append all the list's values to that variable, with a separator between each value (I would recommend the tab character (\t)).
    Then when the form is submitted, your request.getParameter("allList") will contain a long string containing all the values, tab-separated, that you can use StringTokenizer on to get each individual value. Make sense?

  • Infopath Drop Down List not showing all items in a list

    I have an Infopath form where I have a vendor drop down and then I filter the product list based on the vendor. The problem is the drop down list is only filtering through the first 100 records. I added a second drop down with the model#'s and no filter and there is only 100 values showing. I checked the All Items view and it is set to display all records. Does anyone know how to fix this?

    Hi all,
    If I want a drop down list in InfoPath (data coming from a SharePoint list) to be in a particular order I query the SharePoint list via this method
    http://blogs.msdn.com/infopath/archive/2007/01/15/populating-form-data-from-sharepoint-list-views.aspx
    You can create a data connection to a particular view in SharePoint - make sure that view is sorted how you want it to be and the item limit is set to 9999.
    You do not need code for this method and it works in browser enabled forms.
    The people picker (which also works in browser enabled forms) http://metahat.blogspot.com/2007/05/people-picker-control-for-infopath-2007.html can help with those of you trying to get a list of users.
    Cheers.

  • Count of items ina list using CAML Query

    Hi,
    Thanks in Advance
    I'm using an app called blumshapiro to customize the tile in sharepoint 2013, I also have a requirement of getting the item count from the list which can be done by writing a CAML Query. Can anyone please assist me with the syntax to fetch the item count
    in caml Query.
    Regards,
    Niranjan

    Hi 
    There is nothing like item count in Camel query.You can get Required result using SPListItemCollection.Count
    Do a normal where clause having condition.
    SPQuery query = new SPQuery();
    string camlquery = @"<Query>
    <Where>
    <Eq>
    <FieldRef Name='Vendor_x0020_Product_x0020_Name'/>
    <Value Type='Text'>" + xpathresultBTADSLMAX + @"</Value>
    </Eq>
    </Where>
    </Query>";
    query.Query = camlquery;
    SPListItemCollection listItemCollection = list.GetItems(query);int count=0;if(listItemCollection !=null) { count=ListItemCollection.Count}MSDN reference
    http://msdn.microsoft.com/en-us/library/ms467521.aspx
    Regards, Rajendra Singh If a post answers your question, please click Mark As Answer on that ost and Vote as Helpful http://sharepointundefind.wordpress.com/

  • SharePoint: Workflow to retrieve all users and Create list item record for each user

    Hi all,
    My share point site have two Lists as Holidays and MyCalender.
    Actually Holiday is simple non-Calender list with field as Holiday Date, Reason. MyCalender List Calender type list with Person Look-up column and user can see his own record. User of Manager group will declare holiday. This Holiday should get reflected
    on each user 's MyCalender List.[One listitem as holiday date and reason for each user] so everyone can view that record.
    I have requirement as Manager will create one Holiday record and then run single workflow so for all users present in SharePoint Site, one MyCalender List Item record should get created. Is it possible to do using Workflow?? Please help as I didn't get any
    solution for this.. Thanks in advance!

    You don't need one workflow per user when a filtered view can do this for you.  If the manager's list is the parent calendar, I'm assuming that he'll be at least using the person look-up column.
    Whether this feeds through the MyCalendar or stays where it is, you can use the [Me] parameter within the filter on a new view.  This will then return the assigned holiday filtering against the account that is logged in.
    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles:
    CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

  • Sharepoint Online: Find an Item box is not finding all items in a list based on keyword search

    I am using SharePoint Online.
    I have a standard SharePoint list with a "Name" field (single line of text) and a "Description" field (multiple lines of text).  The Find n Item search box is present as expected, and works very sporadically.  For example, I
    have an item with the word "white" in the Description field.  Searching for "white" doesn't find the item.  I have a number of items with the word "vending" in the Name field.  Searching for vending returns some
    of the items, but not all of them.  
    I have gone into the list settings (Advanced) and reindexed the list.
    Here are two screenshots that illustrate the issue.  The first is unfiltered. The second shows a filter on the word "vending".  Note that some are found and some are not.
    Filtered
    Any idea what's going on?  

    I am also experiencing an issue with the find. If not the same issue David is having, I suspect it is related, so I will describe it here.
    I created a list based on the Contacts content type and within a standard list view, entering values in the "Find an item" box will match content of some columns, but not others. The four columns that the find misses are Position(renamed from Job Title),
    Email Address, Mobile Phone, and Years Of Service (a Numeric column I added to the list). I too have re-indexed the list and retested after several hours.
    Full Name and Email Address are both native columns of the Contact content type and both are Single line of text. I am able to filter the list by finding partial matches on Full Name, but not Email Address.

  • How to find if all items in a list containing the selected color

    Hi
    I'm using the code below to check what color the user has selected. This is only working when my item got one color. Now I would like to change my code so each item can have one or more colors (seperated by semicolon). I guess
    I have to use string.IndexOf but I don't know how to use it in the .Where scentence below to return all the items that got the selected color.
    Thanks, Sigurd F
    var sampleDataGroups = await SampleDataSource.GetGroupsAsync();
    sampleDataGroups = sampleDataGroups.Where<SampleDataGroup>(Item => Item.Color == KeywordColorList.SelectedValue.ToString()).ToList();

    If the Color property of the SampleDataGroup class contains a string with different colours separated by a semicolon you could use the following code to determine whether the KeywordColorList.SelectedValue property is amont these colours:
    var sampleDataGroups = await SampleDataSource.GetGroupsAsync();
    sampleDataGroups = sampleDataGroups.Where<SampleDataGroup>(Item => Item.Color.Split(';').Contains(KeywordColorList.SelectedValue.ToString())).ToList();
    Compilable sample code:
    var sampleDataGroups = new List<SampleDataGroup>
    new SampleDataGroup { Color = "blue"},
    new SampleDataGroup { Color = "blue;red;green"},
    new SampleDataGroup { Color = "red;green"},
    string selectedValue = "blue";
    sampleDataGroups = sampleDataGroups.Where<SampleDataGroup>(Item => Item.Color.Split(';').Contains(selectedValue)).ToList();
    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

  • Is there a way the "i" can be forced on all songs in your list that are broken, then print a list of every song? thx

    I posted a similar question about a half hour ago, but I have no idea where it went. Sorry for the redundancy.
    Hopefully the title says it all. Without clicking on each darn song I would like EVERY song in my library to show the "i" exclamation mark, and then I would like to be able to print a list of all my songs so I can figure out which I need to re-install. I lost connection to a bunch of songs after a Windows 7 update.
    Thank you,

    Your other post is here.
    This happens if the file is no longer where iTunes expects to find it. Possible causes are that you or some third party tool has moved, renamed or deleted the file, or that the drive it lives on has had a change of drive letter. It is also possible that iTunes has changed from expecting the files to be in the pre-iTunes 9 layout to post-iTunes 9 layout, or vice versa, and so is looking in slightly the wrong place.
    Select a track with an exclamation mark, use Ctrl-I to get info, then cancel when asked to try to locate the track. Look on the summary tab for the location that iTunes thinks the file should be. Now take a look around your hard drive(s). Hopefully you can locate the track in question. If a section of your library has simply been moved, or a drive letter has changed, it should be possible to reverse the actions.
    Alternatively, as long as you can find a location holding the missing files, then you should be able to use my FindTracks script to reconnect them to iTunes .
    If you just want a list of what is currently broken use this technique...
    Lost & Found
    Create a playlist called Found, select everything in Music and drag it into the Found playlist. Create a smart playlist called Lost matching All the rules Playlist is Music and Playlist is not Found. Your lost tracks will be in this playlist.
    tt2

  • I have had my I pad 2 for about six weeks with very little to complain about until today. My problem is that Sarfri ikeeps freezing or will not open at all.  I have tried shutting it down then when I reopen it still has the same page up ! Help,

    What should I do?

    Try clearing its cache (Settings > Safari > Clear Cache and also Clear History), and also try closing the app completely : from the home screen (i.e. not with Safari 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Safari app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    If that doesn't work then you could try a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • Join two list with condition using caml query in SharePoint 2013 with client object model

    Hi,
    Want to join two list to get all fields from both list.
    Am new to sharepoint and sharepoint 2013. Am working in sharepoint 2013 online apps. Am using context.executeQueryasync to load list and get items from list. Am able to get items from single list with caml query, but not able to get both list field values
    with joins.  I did lot of surfing..but not..
    Below is my code..
    ListName1 : "AssignedTasks"
    ListName2 : "Tasks"
     var assignedQueryTest = "<View><Joins><Join Type='INNER' ListAlias='Tasks'><Eq><FieldRef Name='TaskId' RefType='Id'/><FieldRef List='Tasks' Name='ID' /></Eq></Join></Joins>"
                    + "<ViewFields><FieldRef Name='TitleValue' /><FieldRef Name='ActionItemsValue' /></ViewFields>"
                    + "<ProjectedFields>"
                    + "<Field Name='TitleValue' Type='Lookup' List='Tasks' ShowField='Title' /><Field Name='ActionItemsValue' Type='Lookup' List='Tasks' ShowField='ActionItems' />"
                    + "</ProjectedFields>"
                    + "</View>";
                   var web = context.get_web();
                    var list = web.get_lists().getByTitle("AssingedTasks");
                    var myQuery = new SP.CamlQuery();
                    myQuery.set_viewXml(assignedQueryTest);
                    var myItems = list.getItems(myQuery, "Include(TitleValue,ActionItemsValue)");
                    context.load(myItems);
                    context.executeQueryAsync(function () { if(myItems.get_count()>0){....}
    }, errorCallback);
    Here am able to get "AssignedTasks" list field values but not able to get "Tasks" list field values. 
    Can you please help me to resolve the issue. Or new idea for join. I have add the condition also in the query.
    If anybody have good sample, please provide.
    Thanks,
    Pariventhan
    Pariventhan.S

    Hi Pariventhan,
    I don't know about join but I have a workaround of this problem.
    Declare one variable (itemcollection) globally. Load all the items "AssignedTasks" using context.load.
    In the success method call another CAML query using <IN> tag of the ID of the items from the second list (Assuming you have look-up column of the ID of the first list to the second list).
    If this is not clear to you then please let me know. If possible then I can provide code sample.
    Thanks,
    Aniruddha

  • Retrieve permision levels for all items in list programatically

    Hi all,
    I need to retrieve all permission levels for all items in a list programatically using client object model in sharepoint 2010.Please send me the code sample.
    Regards,
    Praveen

    Hi Praveen,
    This blog has the code that you are looking for -
    http://www.learningsharepoint.com/2010/07/27/programatically-get-permissions-for-list-and-item-client-object-model-sharepoint-2010/
    or this forum for an idea -
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/6b16b407-203b-4c5b-9605-713904e9b22e/sharepoint-2010-how-to-get-a-list-of-permissions-for-each-individual-user?forum=sharepointadminprevious
    Hope this helps!
    MCITP: SharePoint 2010 Administrator
    MCTS - MOSS 2007 Configuring, .NET 2.0
    | SharePoint Architect | Evangelist |
    http://www.sharepointdeveloper.in/
    http://ramakrishnaraja.blogspot.com/

Maybe you are looking for

  • How to remove credit card from iphone4s

    how to remove credit card from iphone4s

  • Invalid Node Structure, Mac Not Starting

    *THE PROBLEM* My MacBook does not start. All I see when I press the power button is a gray screen with an apple logo and a spinning wheel. *WHAT CAUSED THE PROBLEM* I changed the input languages settings in international in system preferences to “Dev

  • Problem with MASTER_IDOC_DISTRIBUTE

    Hi all. I'm using the FM 'MASTER_IDOC_DISTRIBUTE' to create IDOCs. I'm having the following problem: when I execute this function, it creates the IDOC and transfer it by XML, and the STATUS (you can look in transaction WE20) is set to 03 (IDOC genera

  • Is iOS 6.0.1 effects home button?

    Is iOS 6.0.1 will effects home button? my iPhone 4 home button seems not really sensitive now and need to press few times then only able to exit the application. How to check is the home button issue?

  • Passing blackberry contacts to iphone or excel or other compatible format - how can it be done

    Hi, I am trying to pass my address book from blackberry to iphone, does anyone know how it can be done. Or how can i convert my blackberry address book into excel format? any advice welcome... am pulling my hair out here!