0

I have a sharepoint list with some items in it. I need to retreive the list items in a notepad with all fields separated by |. eg: abc|abc| etc. Require code to retreive the list items in a notepad or text file.

2
  • Have you considered just exporting this to Excel as CSV? - unless you are looking at automating this as a repeteable activity Commented Jan 21, 2014 at 9:59
  • I have already done exporting to excel.its workign fine. But user wants this in notepad format.Because thee ae many processors running in the system and as the list is huge not able to retreive the list items in excel quickly. So user want it to be in notepad format.So they can open with excel.
    – priya
    Commented Jan 21, 2014 at 10:05

2 Answers 2

1

Try using the below code,

StringBuilder MyStringBuilder = new StringBuilder;
  foreach (SPListItem listItem in listitem.Items)
    {
        for (int i = 0; i < listitem.Fields.Count; i++)
        {

                MyStringBuilder.append((String.Format("{0,-19}\t", listItem[i]));               
        }
        Console.WriteLine();
    }
    using (System.IO.TextWriter writer = new System.IO.StreamWriter("c:\\abc.txt"))
    writer.Write(MyStringBuilder.ToString());
1
  • 2
    Be aware this approach is not scaling well for large list. if that is the case, beside improving list indexed columns, etc. for querying - rather use CAML Query (object SPQuery) to retrieve list items (while limiting output only to ) prior to looping through results. Commented Jan 21, 2014 at 11:56
1
$MyWeb.Lists["ListName"].Items |
     ForEach-Object{
          New-Object PSObject -Property @{
                                          Column1=$_["Column Name in SharePoint"]
                                          Column2=$_["Column Name in SharePoint"]                  
                                         }
     } | Export-Csv -path 'C:\FilePath\Filename.csv'

http://social.technet.microsoft.com/Forums/scriptcenter/en-US/c284bca0-def8-4493-8136-3949f8b62ced/export-sharepoint-2010-list-items-into-csv-file-using-managment-shell?forum=ITCG

if for example the above is not fine as its for end users than youll have to custom code!

you have 3 options!

1) save the list to excel and in excel save as csv....

2) use powershell - no go for end users

3) write cutom feature that is attached to the list!

EDIT

as an example:

http://exportlistdatatocsv.codeplex.com/

todo it programmatically you have:

http://www.c-sharpcorner.com/uploadfile/bhushangawale/export-sharepoint-list-programmatically/

or

http://www.arboundy.com/2011/12/dump-all-the-lists-in-a-sharepoint-web-to-excel-csv-files/

2
  • I have already tried using powershell script. As this requirent is on 2007 platform. The object model in powershell doesn't support. So i have written a console application. Everything seems to work fine. But now need to save the list items to a text file thats the requirement.
    – priya
    Commented Jan 21, 2014 at 10:30
  • just ammended my answer!
    – Ali Jafer
    Commented Jan 21, 2014 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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