24 Ağustos 2015 Pazartesi

Sharepoint Read From Csv File to fill SP List By using Site Language (Event Receiver)

Merhaba,
Event Receiver  kullanarak Csv file'den okunan verilerin sharepoint listesine eklenmesi için yaptığım basit çalışmayı paylaşmak istedim.

----------------------------------------------------------------------------------------

 public override void FeatureActivated(SPFeatureReceiverProperties properties)
   {
            using (SPWeb spWeb = (properties.Feature.Parent as SPWeb))

            {
             uint languageid = (uint)spWeb.Language;
             string filePath;
                if (languageid == 1055) //Turkish or not
                {
                 filePath =           SPUtility.GetVersionedGenericSetupPath(@"TEMPLATE\LAYOUTS\iso27001\TestTr.csv", 15);
                }
                else
                {
                filePath =      SPUtility.GetVersionedGenericSetupPath(@"TEMPLATE\LAYOUTS\iso27001\TestEng.csv", 15);
                }

               SPList myList = spWeb.Lists["listname"];
                while ((line = file.ReadLine()) != null)
                {
                  
                    String[] Array = line.ToString().Split('\t');
                 

                StreamReader file;


                file = new StreamReader(filePath);

                    SPListItem newEntry = myList.Items.Add();

                    newEntry["Title"] = Array[0];
                    newEntry["Test1"] = Array[1];
                    newEntry["Test2"] = Array[2];

                    newEntry["Test3"] = Array[3];
                    newEntry.Update();
                    myList.Update();
               }



                file.Close();

                file.Dispose();
           }

    }

Hiç yorum yok:

Yorum Gönder