With sharepoint 2013,
I try change content of a file in Document Library by change content in database, by code:
// Run with user have permission log to DataBase of Sharepoint SPSecurity.RunWithElevatedPrivileges(delegate() { using (var spSite = new SPSite(site.ID)) { spConnection = new SqlConnection(spSite.ContentDatabase.DatabaseConnectionString); spConnection.Open(); //string selectSql = string.Format("SELECT [Content] FROM dbo.DocStreams WHERE [DocId] = '{0}' and BSN = (Select Max(BSN) FROM dbo.DocStreams WHERE [DocId] = '{0}')", file.UniqueId); //var selectCommand = new SqlCommand(selectSql, spConnection); //oldContents = Encoding.UTF8.GetString((byte[])selectCommand.ExecuteScalar()); string updateCommandText = string.Format("UPDATE dbo.AllDocs SET Size = {0} WHERE Id = '{1}'", fileSize, file.UniqueId); var updateCommand = new SqlCommand(updateCommandText, spConnection); var contentDataAdapter = new SqlDataAdapter(); contentDataAdapter.UpdateCommand = updateCommand; contentDataAdapter.UpdateCommand.ExecuteNonQuery(); updateCommandText = string.Format("UPDATE dbo.DocStreams SET [Content] = @BinaryData, Size = {1} WHERE [DocId] = '{0}' AND BSN = (Select Max(BSN) FROM dbo.DocStreams WHERE [DocId] = '{0}')", file.UniqueId, content.Length); updateCommand = new SqlCommand(updateCommandText, spConnection); updateCommand.Parameters.AddWithValue("@BinaryData", content); updateCommand.ExecuteNonQuery(); spConnection.Close(); } });
then, i get error "Colbat exception" when read content of file.
Please help me