2014-12-14 3 views
1

Я хотел бы импортировать \ экспортировать файл из базы данных Sharepoint 2013 через C#. Вы знаете, как это сделать? Поскольку файл в SharePoint зашифрован.SharePoint Foundation 2013 IMPORT EXPORT dbo.allDocs файл файлы

Мой вопрос: Как импортировать \ экспортировать файл в C# из базы данных SharePoint Foundation 2013?

enter image description here

CREATE SCRIPT [DBO] [AllDocs]

CREATE TABLE [dbo].[AllDocs](
    [Id] [uniqueidentifier] NOT NULL, 
    [SiteId] [uniqueidentifier] NOT NULL, 
    [DirName] [nvarchar](256) NOT NULL, 
    [LeafName] [nvarchar](128) NOT NULL, 
    [Level] [tinyint] NOT NULL, 
    [ParentId] [uniqueidentifier] NOT NULL, 
    [DeleteTransactionId] [varbinary](16) NOT NULL, 
    [WebId] [uniqueidentifier] NOT NULL, 
    [ListId] [uniqueidentifier] NULL, 
    [DoclibRowId] [int] NULL, 
    [Type] [tinyint] NOT NULL, 
    [SortBehavior] [tinyint] NOT NULL, 
    [Size] [int] NULL, 
    [ETagVersion] AS (case when [InternalVersion] IS NULL then NULL else ([InternalVersion]+[BumpVersion]*(256))/(256) end), 
    [EffectiveVersion] AS (case when [InternalVersion] IS NULL then NULL else [InternalVersion]+[BumpVersion]*(256) end), 
    [InternalVersion] [int] NULL, 
    [ContentVersion] [int] NOT NULL, 
    [NextBSN] [bigint] NULL, 
    [MetadataNextBSN] [bigint] NULL, 
    [StreamSchema] [tinyint] NULL, 
    [HasStream] AS (case when [Type]=(0) AND ([DocFlags]&(256))=(256) AND [SetupPath] IS NULL OR [SetupPath] IS NOT NULL AND ([DocFlags]&(64))=(64) then (1) else (0) end), 
    [BumpVersion] [tinyint] NOT NULL, 
    [UIVersion] [int] NOT NULL, 
    [Dirty] AS (case when [BumpVersion]<>(0) then CONVERT([bit],(1)) else CONVERT([bit],(0)) end), 
    [ListDataDirty] [bit] NOT NULL, 
    [DocFlags] [int] NULL, 
    [ThicketFlag] [bit] NULL, 
    [CharSet] [int] NULL, 
    [ProgId] [nvarchar](255) NULL, 
    [TimeCreated] [datetime] NOT NULL, 
    [TimeLastModified] [datetime] NOT NULL, 
    [NextToLastTimeModified] [datetime] NULL, 
    [MetaInfoTimeLastModified] [datetime] NULL, 
    [TimeLastWritten] [datetime] NULL, 
    [SetupPathVersion] [tinyint] NOT NULL, 
    [SetupPath] [nvarchar](255) NULL, 
    [SetupPathUser] [nvarchar](255) NULL, 
    [CheckoutUserId] [int] NULL, 
    [DraftOwnerId] [int] NULL, 
    [CheckoutDate] [datetime] NULL, 
    [CheckoutExpires] [datetime] NULL, 
    [VersionCreatedSinceSTCheckout] [bit] NOT NULL, 
    [LTCheckoutUserId] AS (case when ([DocFlags]&(32))=(32) then [CheckoutUserId] end), 
    [CheckinComment] [nvarchar](1023) NULL, 
    [IsCheckoutToLocal] AS (case when ([DocFlags]&(512))=(512) then (1) else (0) end), 
    [VirusVendorID] [int] NULL, 
    [VirusStatus] [tinyint] NULL, 
    [VirusInfo] [nvarchar](255) SPARSE NULL, 
    [VirusInfoEx] [varbinary](max) NULL, 
    [MetaInfo] [dbo].[tCompressedBinary] NULL, 
    [MetaInfoSize] [int] NULL, 
    [MetaInfoVersion] [int] NOT NULL, 
    [UnVersionedMetaInfo] [dbo].[tCompressedBinary] NULL, 
    [UnVersionedMetaInfoSize] [int] NULL, 
    [UnVersionedMetaInfoVersion] [int] NULL, 
    [WelcomePageUrl] [nvarchar](260) NULL, 
    [WelcomePageParameters] [nvarchar](max) NULL, 
    [IsCurrentVersion] [bit] NOT NULL, 
    [AuditFlags] [int] NULL, 
    [InheritAuditFlags] [int] NULL, 
    [UIVersionString] AS ((CONVERT([nvarchar],[UIVersion]/(512))+'.')+CONVERT([nvarchar],[UIVersion]%(512))), 
    [ScopeId] [uniqueidentifier] NOT NULL, 
    [BuildDependencySet] [varbinary](max) NULL, 
    [ParentVersion] [int] NULL, 
    [ParentVersionString] AS ((CONVERT([nvarchar],[ParentVersion]/(512))+'.')+CONVERT([nvarchar],[ParentVersion]%(512))), 
    [TransformerId] [uniqueidentifier] NULL, 
    [ParentLeafName] [nvarchar](128) NULL, 
    [CtoOffset] [smallint] NULL, 
    [Extension] AS (case when charindex(N'.',[LeafName] collate Latin1_General_BIN)>(0) then right([LeafName],charindex(N'.',reverse([LeafName]) collate Latin1_General_BIN)-(1)) else N'' end), 
    [ExtensionForFile] AS (case when [Type]=(0) AND charindex(N'.',[LeafName] collate Latin1_General_BIN)>(0) then right([LeafName],charindex(N'.',reverse([LeafName]) collate Latin1_General_BIN)-(1)) else N'' end), 
    [ItemChildCount] [int] NOT NULL, 
    [FolderChildCount] [int] NOT NULL, 
    [FileFormatMetaInfo] [varbinary](max) NULL, 
    [FileFormatMetaInfoSize] [int] NOT NULL, 
    [FFMConsistent] [bit] NULL, 
    [ListSchemaVersion] [int] NULL, 
    [ClientId] [varbinary](16) NULL, 
CONSTRAINT [AllDocs_ParentId] PRIMARY KEY CLUSTERED 
(
    [SiteId] ASC, 
    [DeleteTransactionId] ASC, 
    [ParentId] ASC, 
    [Id] ASC, 
    [Level] ASC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = ON, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 95) ON [PRIMARY] 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] 

Я стараюсь использовать это:.

1 Код:

-- To allow advanced options to be changed. 
EXEC sp_configure 'show advanced options', 1 
GO 
-- To update the currently configured value for advanced options. 
RECONFIGURE 
GO 
-- To enable the feature. 
EXEC sp_configure 'xp_cmdshell', 1 
GO 
-- To update the currently configured value for this feature. 
RECONFIGURE 
GO 

2 Код

DECLARE @Command  VARCHAR(4000), 
     @FileID  VARCHAR(128), 
     @MyFilename nvarchar(max) 

DECLARE curFile CURSOR FOR    -- Cursor for each image in table 
SELECT DocId FROM [WSS_Content].[dbo].[DocStreams] 

OPEN curFile 

FETCH NEXT FROM curFile 
INTO @FileID 

WHILE (@@FETCH_STATUS = 0) -- Cursor loop 
    BEGIN 
-- Keep the bcp command on ONE LINE - SINGLE LINE!!! - broken up for presentation 

SELECT @MyFilename = LeafName from [WSS_Content].[dbo].[AllDocs] WHERE Id = @FileID 

    SET @Command = 'bcp "SELECT Content from [WSS_Content].[dbo].[DocStreams] WHERE DocId = ''' + 
    @FileID + '''" queryout "C:\' + 
    @MyFilename+'" -T -n -Slocalhost -fC:\bcp.fmt' 

    PRINT @Command -- debugging 

    EXEC xp_cmdshell @Command  -- Carry out image export to file from db table 

    FETCH NEXT FROM curFile 
    INTO @FileID 
    END -- cursor loop 

CLOSE curFile 

DEALLOCATE curFile 

Но я получаю сообщение об ошибке:

enter image description here

ответ

0

It`s просто импортировать файл экспорта \ в C#, потому что это двоичный файл ВЫБРАТЬ Content из [ WSS_Content]. [Dbo]. [DocStreams]

Смежные вопросы