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.

  • 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


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]));               
    using (System.IO.TextWriter writer = new System.IO.StreamWriter("c:\\abc.txt"))
  • 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
$MyWeb.Lists["ListName"].Items |
          New-Object PSObject -Property @{
                                          Column1=$_["Column Name in SharePoint"]
                                          Column2=$_["Column Name in SharePoint"]                  
     } | Export-Csv -path 'C:\FilePath\Filename.csv'


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!


as an example:


todo it programmatically you have:




  • 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.