Sharepoint 데이터베이스에서 파일을 추출하기 위해 C#에서 작은 프로그램을 만들려고합니다. 온라인에서 검색 코드를 얻었고 SharePoint 데이터베이스에서 폴더를 유지하면서 특정 폴더로 파일을 추출하도록 편집하려고합니다.Sharepoint 데이터베이스에서 파일 압축 해제
특히 양식에서 서버의 이름, 파일을 추출하려는 데이터베이스의 이름 및 파일을 추출하는 데 사용하려는 경로를 사용자가 입력하도록합니다.
디버깅 할 때 오류가 발생합니다.
오류 상태 : Could not find a part of the path:
코드 행에 대해서는 다음은
FileStream fs = new FileStream(txtdir.Text + "/" + DirName + "/" + LeafName,
FileMode.Create, FileAccess.Write);
내 코드입니다 :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
namespace SPEXTRACTOR
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void ENTER_Click(object sender, EventArgs e)
{
string DBConnString = "Server=" + txtserver.Text + ";Database="
+ txtDB.Text + ";Trusted_Connection=True;";
SqlConnection con = new SqlConnection(DBConnString);
con.Open();
SqlCommand com = con.CreateCommand();
com.CommandText = "SELECT ad.SiteId, ad.Id, ad.DirName," +
" ad.LeafName, ads.Content" +
" FROM AllDocs ad, AllDocStreams ads" +
" WHERE ad.SiteId = ads.SiteId" +
" AND ad.Id = ads.Id" +
" AND ads.Content IS NOT NULL" +
" Order by DirName";
//SqlCommand com = con.CreateCommand();
//com.CommandText = "select DirName, LeafName, Content
from AllDocStreams, AllDocs
where (LeafName like '%.doc' or LeafName like '%.xls'
or LeafName like '%.pdf' or LeafName like '%.ppt')
and Content is not NULL";
//com.CommandText = "select DirName, LeafName, Content
from AllDocStreams, AllDocs
where (LeafName like '%.doc' or LeafName like '%.xls'
or LeafName like '%.pdf' or LeafName like '%.ppt')
and Content is not NULL";
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
// grab the file's directory and name
string DirName = (string)reader["DirName"];
string LeafName = (string)reader["LeafName"];
if (!Directory.Exists(DirName))
{
Directory.CreateDirectory(DirName);
Console.WriteLine("Creating directory: " + DirName);
}
//FileStream fs = new FileStream(DirName + "/" + LeafName
, FileMode.Create, FileAccess.Write);
FileStream fs = new FileStream(txtdir.Text + "/" + DirName + "/"
+ LeafName, FileMode.Create, FileAccess.Write);
BinaryWriter writer = new BinaryWriter(fs);
// depending on the speed of your network,
//you may want to change the buffer size (it's in bytes)
int bufferSize = 1000000;
long startIndex = 0;
long retval = 0;
byte[] outByte = new byte[bufferSize];
// grab the file out of the db one chunk (of size bufferSize) at a time
do
{
retval = reader.GetBytes(4, startIndex, outByte, 0, bufferSize);
//retval = reader.GetBytes(2, startIndex, outByte, 0, bufferSize);
startIndex += bufferSize;
writer.Write(outByte, 0, (int)retval);
writer.Flush();
} while (retval == bufferSize);
// finish writing the file
writer.Close();
fs.Close();
Console.WriteLine("Finished writing file: " + LeafName);
}
// close the DB connection and whatnots
reader.Close();
con.Close();
}
}
}
디버깅 또는 값이 문제가 줄에 예상되는 전체 경로입니다 무엇을 쓸 수 있을까? –
첫 번째 반복. – Jeff
예 : 파일을 c : \aa – Jeff