SharePoint Foundation 2013 IMPORT \ EXPORT dbo.allDocs文件\ files

时间:2014-12-14 10:05:28

标签: c# sharepoint

我想通过C#从Sharepoint 2013数据库导入\ export文件。你知道怎么做吗?因为SharePoint中的文件已加密。

我的问题是:如何从SharePoint Foundation 2013数据库导入C#中的导出文件?

enter image description here

创建脚本[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

1 个答案:

答案 0 :(得分:0)

在C#中导入\ export文件很简单,因为它是二进制文件来自[WSS_Content]的SELECT内容。[dbo]。[DocStreams]