2017-03-08 19 views
-2

私は、employeeProfileというSP2010を使用してwebpartを開発しています。 私の問題は、webpart HTMLページに画像を表示できないことです。リモートサーバーからエラーが返されました:(401)Unauthorized。Sharepointアクセス表示イメージ

これは、HTMLコードです:

<img alt="User Pic" src=<%#Eval("Photo")%>> 

using (SPSite site1 = new SPSite(SPContext.Current.Site.ID, userToken)) 
       { 
        using (SPWeb web1 = site1.OpenWeb(SPContext.Current.Web.ID)) 
        { 
         //GET EMPLOYEE INFORMATION FROM LIST EMPLOYEE 
         SPList employee = web1.Lists["Employee"]; 
         SPQuery Query = new SPQuery(); 
         Query.Query = "<Where>" + 
             "<Eq><FieldRef Name='Windows_x0020_ID' /><Value Type='User'>" + 
             currentUser + "</Value></Eq>" + 
             "</Where><OrderBy>" + 
             "<FieldRef Name='Created' />" + 
             "</OrderBy>"; 
         Query.RowLimit = 1; 
         SPListItemCollection ColItem = employee.GetItems(Query); 
         if (ColItem.Count > 0) 
         { 
          SPListItem getItem = ColItem[0]; 

          DataTable dataTable = new DataTable(); 
          dataTable = ColItem.GetDataTable(); 
          dataTable.Columns.Add("Photo").DefaultValue = ""; 
          if (getItem.Attachments.Count > 0) 
          { 
           SPFile file = null; 
           for (int i = 0; i < getItem.Attachments.Count; i++) 
           { 
            file = getItem.ParentList.ParentWeb.GetFile(getItem.Attachments.UrlPrefix + getItem.Attachments[i].ToString()); 
            //dataTable.Columns.Add("Photo").DefaultValue = SPContext.Current.Site.RootWeb.Url.ToString() + "" + "/" + file. 
           } 
           foreach (DataRow row in dataTable.Rows) 
           { 
            row["Photo"] = SPContext.Current.Site.RootWeb.Url.ToString() + "" + "/" + file.Url; 
           } 
          } 
          dataEmployee.DataSource = dataTable; 
          dataEmployee.DataBind(); 
         } 

答えて

0

これは、アクセス許可の問題かもしれません。ユーザーはウェブにアクセスできますか? SPSecurity.RunwithElevatedPrevilageを使用します。これはあなたを助けるかもしれません。

<img alt="User Pic" src=<%#Eval("Photo")%>SPSecurity.RunWithElevatedPrivileges(delegate(){ 
    using (SPSite site1 = new SPSite(SPContext.Current.Site.ID, userToken)) 
      { 
       using (SPWeb web1 = site1.OpenWeb(SPContext.Current.Web.ID)) 
       { 
        //GET EMPLOYEE INFORMATION FROM LIST EMPLOYEE 
        SPList employee = web1.Lists.TryGetList("Employee"); 
        SPQuery Query = new SPQuery(); 
        Query.Query = "<Where>" + 
            "<Eq><FieldRef Name='Windows_x0020_ID' /><Value Type='User'>" + 
            currentUser + "</Value></Eq>" + 
            "</Where><OrderBy>" + 
            "<FieldRef Name='Created' />" + 
            "</OrderBy>"; 
        Query.RowLimit = 1; 
        SPListItemCollection ColItem = employee.GetItems(Query); 
        if (ColItem.Count > 0) 
        { 
         SPListItem getItem = ColItem.FirstOrDefault(); 

         DataTable dataTable = new DataTable(); 
         dataTable = ColItem.GetDataTable(); 
         dataTable.Columns.Add("Photo").DefaultValue = ""; 
         if (getItem.Attachments.Count > 0) 
         { 
          SPFile file = null; 
          for (int i = 0; i < getItem.Attachments.Count; i++) 
          { 
           file = getItem.ParentList.ParentWeb.GetFile(getItem.Attachments.UrlPrefix + getItem.Attachments[i].ToString()); 
           //dataTable.Columns.Add("Photo").DefaultValue = SPContext.Current.Site.RootWeb.Url.ToString() + "" + "/" + file. 
          } 
          foreach (DataRow row in dataTable.Rows) 
          { 
           row["Photo"] = SPContext.Current.Site.RootWeb.Url.ToString() + "" + "/" + file.Url; 
          } 
         } 
         dataEmployee.DataSource = dataTable; 
         dataEmployee.DataBind(); 
        } 
        } 
        } 
        } 
        ); 
関連する問題