Retrieve the sharepoint list information to text file .

Posted by Ptharak under SharePoint on 1/10/2011 | Points: 10 | Views : 2998 | Status : [Member] | Replies : 3
How To write sharepoint list information to text file .
Ex: In my site , I have created one list. In that list added some items in list..

I need to those information in text file like Title,Id, Created By,Modified.

How these things write in text file...




Thanks & Regards
nadh




Responses

Posted by: Karthikanbarasan on: 1/10/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Check this if it would help you... Not sure if it will solve ur problem...

SPSecurity.RunWithElevatedPrivileges(delegate() {

using (StreamWriter sw = new StreamWriter(@"C:\log.txt"))
{
//log information here
}
});


Found this information in this site
http://efreedom.com/Question/1-3018576/Logging-TextFile-SharePoint

Thanks
Karthik
www.f5Debug.net

Ptharak, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ptharak on: 1/10/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Karthik,

I written like this, but its not working ....can u tell where I need to modify

public class Events:SPItemEventReceiver
{
public static string fileLoc = @"c:\sample2.txt";
StreamWriter sw = new StreamWriter(fileLoc);
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
try
{
FileStream fs = null;
if (!File.Exists(fileLoc))
{
using (fs = File.Create(fileLoc))
{
sw.WriteLine("Listid :" + properties.ListId.ToString());
sw.WriteLine("Listtile" + properties.ListTitle);

}
}

}
catch (Exception ex)
{
properties.Cancel = true;
properties.ErrorMessage = ex.Message;
throw ex;
}
finally
{
this.sw.Dispose();
}
}

Ptharak, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/10/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
ok, thats great... ill check it out and let u know...

Thanks
Karthik
www.f5Debug.net

Ptharak, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response