小编Jam*_*son的帖子

从当前用户获取直接下属列表

我检查了另外两个线程,甚至使用了一个代码,但它从不填充列表.当我打开Active Directory用户和计算机并转到我在组织下的经理时,我会看到他的直接下属列表.

我想要做的是通过代码访问该列表.到目前为止我找到的任何东西似乎都没有用.

    public void GetDirectoryEntry(string adUserName)
    {
        DirectoryEntry de = new DirectoryEntry("LDAP://server.server.com");

        DirectorySearcher ds = new DirectorySearcher(de);
        ds.Filter = "(&((&(objectCategory=Person)(objectClass=User)))(samaccountname=" + adUserName + "))";
        ds.SearchScope = SearchScope.Subtree;

        SearchResult rs = ds.FindOne();

        string distinguishedName = rs.Properties["distinguishedName"][0].ToString();
        string department = rs.Properties["department"][0].ToString();
        string manager = rs.Properties["manager"][0].ToString();
        //string temp3 = rs.Properties["Reports"][0].ToString();

    }
Run Code Online (Sandbox Code Playgroud)

我尝试过使用Reports并且directReports两者都没有出错.

此方法加载登录用户或我传入其中的任何用户.我可以访问他们所有的属性,但我似乎无法访问他们的直接报告.

我错过了什么?

找到答案:

foreach (string objProperty in rs.Properties["DirectReports"])
            {
                isManager = true;
                string emp = objProperty.ToString();
                string[] setp = new string[1];
                setp[0] = "DC"; //If your …
Run Code Online (Sandbox Code Playgroud)

c# ldap active-directory

7
推荐指数
1
解决办法
4236
查看次数

单击除第一个td之外的行

我试图单击表行并执行操作.但是,如果他们单击第一个<td>单元格,我不希望它执行该操作.

这是我到目前为止的代码:

jQuery('#dyntable tbody tr').live('click', function () {
        nTr = jQuery(this)[0];

        openMessage(oTable, nTr);
    });
Run Code Online (Sandbox Code Playgroud)

这是按预期工作,除了第一个<td>有一个复选框,所以如果他们点击该单元格我不想调用o penMessage(oTable, nTr);函数.

我还需要nTr=行的内容.

jquery datatables

6
推荐指数
2
解决办法
1万
查看次数

错误7运算符'=='无法应用于'object'类型和'bool'类型的操作数

我正在将很多代码从VB.net转换为c#,这是我认为在转换过程中出现的另一个问题.

if (sRow.Cells[1].Value == true)
    Worked = "X";
else if (sRow.Cells[2].Value == true)
    Vacation = "X";
else if (sRow.Cells[3].Value == true)
    Sick = "X";
else if (sRow.Cells[4].Value == true)
    Holiday = "X";
Run Code Online (Sandbox Code Playgroud)

在每个if/else/else if行上它给我这个错误.我确定我错过了一些会迫使我做头脑的东西......

错误7运算符'=='无法应用于'object'类型和'bool'类型的操作数

c# asp.net

6
推荐指数
2
解决办法
9744
查看次数

检查文件是否存在不知道扩展名

有没有一种简单的方法来检查文件是否存在?我知道文件的名称不是扩展名.

该文件的名称将始终是表中的userID.

所以对我来说,我可能是1.*

来自.jpg,.jpeg,.gif的任何内容..png等用于图像格式.

这很容易还是我应该将文件扩展名上传到数据库?

if (System.IO.File.Exists("~/ProfilePictures/" + userID " + ".*"))
   {
   }
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc

6
推荐指数
1
解决办法
7878
查看次数

使用SQLDataReader时"无数据存在时读取无效"

这是我的GeneralFunctions:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for GeneralFunctions
/// </summary>
public class GeneralFunctions
{
    public GeneralFunctions ()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public static DataTable GetData ( string query )
    {
        SqlDataAdapter dataAdapter;
        DataTable table;

        try
        {
            dataAdapter = new SqlDataAdapter( query, GetConnectionString() );
            table = new DataTable();

            dataAdapter.Fill( table );
            return table;
        }
        catch ( Exception ex )
        {
        } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net

5
推荐指数
1
解决办法
1万
查看次数

有没有更好的方法来构造这个if语句

这对我来说似乎一团糟,我的脑海里告诉我必须有一个更好的方法.

我在网页上有6个控件.

if (printer_make_1.Text != "" && printer_model_1.Text != "" && printer_make_2.Text != "" && printer_model_2.Text != "" && printer_make_3.Text != "" && printer_model_3.Text != "")
{
  // Do something
}
Run Code Online (Sandbox Code Playgroud)

最好/最有效的方法是什么?

c# asp.net

4
推荐指数
2
解决办法
183
查看次数

使用ADO.NET从SQL获取单个值

我到目前为止:

// Update status history if the current work flow item has a status
int workflowID = Convert.ToInt32(statusCode.SelectedValue);
string status = "select status from jm_accountworkflowdetail where workid = @workID";

SqlConnection sqlConnection2 = new SqlConnection(sqlDevelopment.ConnectionString);
SqlCommand sqlComm2 = new SqlCommand(status, sqlConnection2);

sqlComm2.Parameters.AddWithValue("@workID", workflowID);
Run Code Online (Sandbox Code Playgroud)

查询将返回一个值('SOC','POS')或(''),表示它没有附加状态.

我需要做的是,如果状态不为空,则执行其他一些代码.但我不知道如何执行所有操作只是为了检查状态是否有值.

c# sql-server ado.net webforms

4
推荐指数
1
解决办法
1万
查看次数

Jquery .click事件

我试图这样做,当他们点击<tr>它将打开一个工作正常的对话框.但是在此<tr>我有一个输入复选框,我需要允许他们点击而不打开对话框.这怎么可能?

$('#messageContainer tr').click(function () {
    var masterMessageID = $(this).attr('messageID');
    var replyToID = $(this).attr('replyToID');

    buildDialog(this.id, masterMessageID, replyToID);
    $(this).removeClass('messageNew');
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<tr replytoid="3" messageid="7078" id="16">
    <td>&nbsp;&nbsp;<input type="checkbox" name="checkAll"></td>
    <td>John Doe</td>
    <td>sdfsdf</td>
    <td>3/14/2012 1:29:47 PM</td>
</tr>
Run Code Online (Sandbox Code Playgroud)

jquery

3
推荐指数
1
解决办法
455
查看次数

循环遍历sql(SQL或Asp.net C#)的最佳方法是什么?

我正在创建一个发送电子邮件的列表.登录的个人在数据库中有一个他们向谁报告的字段(除非出现错误或他们向任何人报告).

因此,例如,如果我登录并单击SQL中的提交按钮,它会说我向'John Doe'报告

然后,我需要抓住"John Doe"报告的人并将其添加到列表中.我需要继续攀登列表,直到我们到达公司的顶部(GID将为空或空).

以我为例,我向'John Doe'谁汇报'Tom Doe'.汤姆向任何人报告他的usrReportsTo领域是这样的'00000000-0000-0000-0000-000000000000'.

如果usrReportsTo场""NULL'00000000-0000-0000-0000-000000000000'循环应该终止.

这是我用过的sql.

执行此循环的最干净/最好/最有效的方法是什么?在SQL或ASP.net C#中更好吗?

select usrReportsTo from dbo.CVT_Users_usr, usrEmailAddress
WHERE RTRIM(usrFirstName) + ' ' + RTRIM(usrLastName) = 'James Wilson' 
-- Returns 'James Wilson' + email

SELECT RTRIM(usrFirstName) + ' ' + RTRIM(usrLastName) as Name, usrEmailAddress, usrReportsTo from dbo.CVT_Users_usr
WHERE usrGID = '38922F83-4B6E-499E-BF4F-EF0B094F47F7'
-- Returns 'John Doe' + email + reportsTo

SELECT RTRIM(usrFirstName) + ' ' + RTRIM(usrLastName) as …
Run Code Online (Sandbox Code Playgroud)

c# sql t-sql asp.net

3
推荐指数
1
解决办法
506
查看次数

UserManager.RemoveFromRoles不删除角色

[HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult EditUser(AspNetUser UserToEdit, string[] roles)
        {
            AspNetUser CurrentUser = db.AspNetUsers.Find(User.Identity.GetUserId());
            AspNetUser UserBeingEdited = db.AspNetUsers.Find(UserToEdit.Id);

            string[] AllRoles = db.AspNetRoles.Select(s => s.Name).ToArray();
            UserManager.RemoveFromRoles(UserBeingEdited.Id, AllRoles);


            // Add all of the roles returned from the webpage
            if (roles.Count() > 0)
            {
                UserManager.AddToRoles(UserBeingEdited.Id, roles);
            }
        }
Run Code Online (Sandbox Code Playgroud)

运行此代码后,我检查用户,用户仍然拥有与之前相同的角色.roles是从我的编辑用户页面返回的角色列表,它已正确填充.

任何人都知道如何让这个工作?没有错误或任何东西.

asp.net-mvc entity-framework

3
推荐指数
1
解决办法
1980
查看次数