# Export subscribers with custom fields

With Sitefinity CMS, you can import and export subscribers to mailing lists. You may also have subscribers with custom fields, for example, *Phone number* or *Company*. By default, Sitefinity CMS does not take any custom fields during import or export of subscribers.

You can export subscribers with custom fields by creating a separate user widget or page for this specific purpose. The following code sample demonstrates how to export subscribers' list from Sitefinity CMS to a *MySubscribers* `CSV` file:

```C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.Sitefinity.Model;
using Telerik.Sitefinity.Modules.Newsletters;
using Telerik.Sitefinity.Newsletters.Model;

namespace SitefinityWebApp
{
   public class CustomSubscribersExport : System.Web.UI.Page
   {
       protected void Page_Load(object sender, EventArgs e)
       {
           string data = this.ExportSubscribersWithCustomFieldsToCommaSeparatedList();

           var response = this.Page.Response;

           response.Clear();
           response.Buffer = true;

           response.ContentEncoding = Encoding.UTF8;
           response.Charset = "utf-8";

           response.ContentType = "application/CSV";
           response.AddHeader("Content-Disposition", "attachment;filename=\"MySubscribers.csv\"");

           response.Write(data);
           response.End();
       }

       private string ExportSubscribersWithCustomFieldsToCommaSeparatedList()
       {
           return this.ExportSubscribersWithCustomFieldsToCommaSeparatedList(Guid.Empty);
       }

       private string ExportSubscribersWithCustomFieldsToCommaSeparatedList(Guid mailingListId)
       {
           var newsLetterManager = NewslettersManager.GetManager();
           IQueryable<Telerik.Sitefinity.Newsletters.Model.Subscriber> subscribers = null;

           if (mailingListId == Guid.Empty)
               subscribers = newsLetterManager.GetSubscribers();
           else
               subscribers = newsLetterManager.GetMailingList(mailingListId).Subscribers();

           var sb = new StringBuilder();
           sb.AppendLine(String.Join(delimiter, subscriberFields));

           foreach (var subscriber in subscribers)
           {
               var subscriberEntry = new List<string>();
               foreach (var field in subscriberFields)
               {
                   if (subscriber.DoesFieldExist(field))
                       subscriberEntry.Add(subscriber.GetValue<string>(field));
                   else
                       subscriberEntry.Add(string.Empty);
               }
               sb.AppendLine(String.Join(delimiter, subscriberEntry));
           }

           return sb.ToString();
       }

       private readonly string delimiter = ", ";

       private string[] subscriberFields = new string[]
        { 
            "Email",
            "FirstName",
            "LastName",
            "PhoneNumber",
            "CompanyName"
        };
   }
}
```

In the code above, you get an instance of the `NewslettersManager` class, and use it to query all subscribers or only subscribers part of a specific mailing list. Next, you iterate through the resulting collection of subscribers and if the desired field exists, you add this value to a string builder. Finally, you modify the page or widget response to generate a `CSV` file containing the field values of subscribers, including the custom fields.
