SharePoint 2010 사이트의 시스템 관리자로 로그인 할 때 오류없이 실행되는 코드 블록이 있습니다. 그러나 나는 일반 사용자 계정으로 같은 것을 실행하는데 문제가있다. 다른 사람이 C# 코드를 사용하여 다른 SharePoint 계정 (관리자 계정)으로 로그인하여 코드 블록을 실행하는 방법을 알려주십시오.SharePoint2010의 서비스 계정에 내 계정을 가장하는 방법
예 :
Using(Domain,LoginID,Password)
{
//Execute Code
//logout as admin
}
SharePoint 2010 제품에 오류 메시지 :
오류가 발생하였습니다 : System.UnauthorizedAccessException : 경로에 액세스 할 'C : \ 프로그램 파일 \ 공용 Files \ Microsoft Shared \ 웹 Server Extensions \ 14 \ template \ layouts \ Test \ Dev \ ABC.xlsx '가 거부되었습니다. System.IO.FileStream.Init (String path, FileMode 모드, FileAccess 액세스, Int32 권한, Boolean useRights, FileShare 공유, Int32 bufferSize, FileOptions 옵션, SECURITY_ATTRIBUTES secAttrs)에서 System.Windows.IO에서 System.Windows.io에서 오류가 발생했습니다. , String msgPath, 부울 bFromProxy) System.IO.FileStream ..ctor의 System.IO.FileStream ..ctor (String 경로, FileMode 모드, FileAccess 액세스, FileShare 공유, Int32 bufferSize, FileOptions 옵션, String msgPath, Boolean bFromProxy) (문자열 경로,하는 FileMode 모드) App.Test.btnFileUpload_Click에서 System.Web.HttpPostedFile.SaveAs (문자열 파일 이름) (개체 보낸 사람, EventArgs입니다 E)
코드 샘플에서 :
if (fileUpload.HasFile)
{
strTarget = Server.MapPath(fileUpload.FileName);
string[] arrCheckExtension = strTarget.Split('.');
if (arrCheckExtension.Length >= 2)
{
if (arrCheckExtension[1].ToString().Equals("xls") || arrCheckExtension[1].ToString().Equals("xlsx"))
{
fileUpload.SaveAs(strTarget);
strConnForExcel = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0;HDR=YES;IMEX=1;""", strTarget);
strQueryForExcel = String.Format("select id from [{0}$]", "Test");
OleDbDataAdapter adap = new OleDbDataAdapter(strQueryForExcel, strConnForExcel);
ds = new DataSet();
adap.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (strids == "")
{
strids += ds.Tables[0].Rows[i]["id"].ToString();
}
else
{
strids += "," + ds.Tables[0].Rows[i]["id"].ToString();
}
}
txtUpload.Text = strids;
}
}
else
{
Response.Write("<script language='javascript'>alert('Please Select File with .xls or xlsx Extension');</script>");
}
}
}
아마도 SharePoint의 layouts-folder가 아닌 다른 곳에서 업로드 한 내용을 저장해야합니다. 이는 보안상의 위험이 있습니다 ... Temp 디렉토리를 사용하거나 새 폴더 (C : \ UploadedFiles)를 만들고 필요한 사용자에게 쓰기 권한이 있는지 확인하십시오. Excel이 어디에 저장 될지 알면 Server.MapPath 명령이 필요하지 않습니다. – artokai