SharePoint-Liste über OLE updaten



  • Hallo.

    Ich habe mir eine DataTable abgeleitet und um ein paar Funktionen für den SharePoint-Zugriff erweitert.

    public struct SharePointConnectionData
        {
            public System.Uri Link;
            public string ListName;
    
            public SharePointConnectionData(System.Uri fLink, string fListName)
            {
                this.Link = fLink;
                this.ListName = fListName;
            }
    
            public string GetConnectionStringForReading() { return "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=1;DATABASE=" + Link.ToString() + "; List=" + ListName; }
    
            public bool IsDefined()
            {
                if(this.Link == null || this.Link.ToString() == string.Empty) { return false; }
                if (this.ListName == null || this.ListName == string.Empty) { return false; }
                return true;
            }
        }
    
    public class MyDataTable : System.Data.DataTable
        {
            #region PUBLIC:
            #region Constructor
            public MyDataTable() : base(){}
    
            public MyDataTable(string TableName) : base() {this.TableName = TableName;}
            #endregion
    
            #region Row and Column access
    
            public System.Data.DataRow GetRowByKeyFromTable(System.Collections.Generic.KeyValuePair<string, string> SearchKey)
            {
                #region Checking if SearchKey is contained in DataTable
                if (!this.Columns.Contains(SearchKey.Key)) { return null; }
                #endregion
    
                #region Search and Return Row
                foreach (System.Data.DataRow Row in this.Rows)
                {
                    if (Row[SearchKey.Key].ToString() == SearchKey.Value.ToString())
                    {
                        return Row;
                    }
                }
    
                return null;
                #endregion
            }
            #endregion
    
            #region Sharepoint connection
            public void InitializeSharePointConnectionData(System.Uri fLink, string fListName) { this.SharePointConnectData.Link = fLink; this.SharePointConnectData.ListName = fListName; }
    
            public void LoadSharePointList()
            {
                #region Local variables
                string strSQL = string.Empty;
                System.Data.OleDb.OleDbCommand cmd = null;
                System.Data.DataSet ds = null;
                System.Data.OleDb.OleDbDataAdapter da = null;
                #endregion
    
                #region GetDataFromSharePoint
                System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(this.SharePointConnectData.GetConnectionStringForReading());
    
                strSQL = "SELECT * FROM LIST";
                cmd = new System.Data.OleDb.OleDbCommand(strSQL, conn);
                ds = new System.Data.DataSet();
    
                ds.Locale = System.Globalization.CultureInfo.InstalledUICulture;
                da = new System.Data.OleDb.OleDbDataAdapter(cmd);
                da.Fill(ds);
                this.Merge(ds.Tables[0]);
                #endregion
    
                #region Clearing
                ds.Dispose();
                da.Dispose();
                #endregion
            }
    
            public void UpdateTableInServerList()
            {
                #region Local variables
                string strSQL = string.Empty;
                System.Data.OleDb.OleDbCommand cmd = null;
                System.Data.DataSet ds = null;
                System.Data.OleDb.OleDbDataAdapter da = null;
                System.Data.DataTable dt = null;
                #endregion
    
                #region GetDataFromSharePoint
                System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(this.SharePointConnectData.GetConnectionStringForReading());
    
                strSQL = "UPDATE * FROM LIST";
                cmd = new System.Data.OleDb.OleDbCommand(strSQL, conn);
                ds = new System.Data.DataSet();
    
                ds.Locale = System.Globalization.CultureInfo.InstalledUICulture;
                da = new System.Data.OleDb.OleDbDataAdapter(cmd);
                da.Update(this.Select(null, null, System.Data.DataViewRowState.ModifiedCurrent));
                #endregion
            }
            #endregion
    
            #region Filter functions
            public void FilterByFilterExpression(string FilterExpression)
            {
                this.FilterByFilterExpressionFkt(FilterExpression);
            }
            #endregion
            #endregion
    
            #region PRIVATE:
            #region Private variables
            SharePointConnectionData SharePointConnectData;
            #endregion
    
            #region Private Functions
            private void FilterByFilterExpressionFkt(string FilterExpression)
            {
                System.Data.DataView dv = new System.Data.DataView(this.Copy());
                this.Clear();
                dv.RowFilter = FilterExpression;
                this.Merge(dv.ToTable());
            }
    
            private string GetFilterExpressionByDataTable(System.Data.DataTable FilterTable)
            {
                string FilterExpression = string.Empty;
    
                return FilterExpression;
            }
            #endregion
            #endregion
        }
    

    Alles läuft ohne Fehler. Allerdings die Funktion UpdateTableInServerList() hat irgendwie keinen Effekt. Die Liste bleibt unverändert. Weiß jemand, warum er die Tabelle nicht zurück schreibt?

    Gibt es auch eine Möglichkeit ÜBER OLE (Zugriff über Microsoft.SharePoint.Client. reicht mir nicht aus!!!!) nur eine Zelle zu verändern, ohne immer gleich die komplette Tabelle hin und her zu laden?

    EDIT: Wenn ich mir eine Row aus der Table herausnehmen, dort einen Eintrag ändere und mir dann den RowState ansehe, so ist dieser "Added"!???! Wieso das?
    Hat das vllt. damit zutun, dass er nicht das Update ausführt?

    Vielen Dank und Grüße,
    CJens


Anmelden zum Antworten