.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Reading users department fails

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :SharePoint

I'm trying to get the currents users department name in a Sharepoint feature, but I get an error when i try to runthe code :  Here the code: 

private string GetUserIdent(SPWeb web, SPSite site)


View Complete Post

More Related Resource Links

List of users by department hyperlinked


Hey Guys,

On our intranet site I have a search function to search the users in Active directory and returns certain criteria (phone number, email etc). What I have been asked for next is a list of departments where when clicked it brings up a list of users in that department, this is as far as I have managed to get. What I need to do next is have each user in this list as a hyperlink so that when you click their name it brings up their details.

My code for departmental search is:

  protected void LinkButton1_Click(object sender, EventArgs e)
        SearchResultCollection results = null;
            string path = "LDAP://server.company.company.company/ou=test,DC=company,DC=company,DC=company";
            DirectoryEntry entry = new DirectoryEntry(path);
            DirectorySearcher mySearcher = new DirectorySearcher(entry);
            mySearcher.Filter = "(&(objectClass=user)(|(department=Accounts*)))";
            results = mySearcher.FindAll();
            foreach (SearchResult searchResult in results)
                Console.WriteLine("Search properties for {0}", searchResult.Path);
                foreach (string propertyKey in searchResult.Prope

login fails for (some) users.


Dear All,

My site (asp.net 2.0 c#)  has 3 login fields, Group, User and Password.  I use forms authentication with the following authentication section in my web.config :

    <authentication mode="Forms">
              name =".LoginCookie"

Most of my users can login no problems, but for about 1 in 5 of them, they receive no error message at all and are thrown immediately back to log in page.

Every login attempt is written to a security log and according to that they passed my own inbuilt validation,

TODATETIMEOFFSET fails only when reading smallint offset value out of a table


SQL Server 2008 R2 Developer

I'm getting a completely bizarre failure with the below repro code.  It ONLY fails in scenario #2, where I get "The timezone provided to builtin function todatetimeoffset is invalid."  I can't for the life of me understand what the difference is between scenario #2 and #3 from the function's perspective.  Once the value is assigned to the local SMALLINT variable, why does it matter where the value came from?

DECLARE	@OrgTimezoneOffset1 INT,
	@OrgTimezoneOffset2 SMALLINT,
	@OrgTimezoneOffset3 SMALLINT

CREATE TABLE dbo.Timezone (
	TimeZoneName VARCHAR(100),
	TimeZoneOffset SMALLINT

INSERT INTO dbo.Timezone
SELECT	'(UTC-07:00) Arizona',

SELECT @OrgTimezoneOffset1 = tz.TimezoneOffset
FROM dbo.Timezone tz
WHERE tz.TimezoneName = '(UTC-07:00) Arizona'

SELECT @OrgTimezoneOffset2 = tz.TimezoneOffset
FROM dbo.Timezone tz
WHERE tz.TimezoneName = '(UTC-07:00) Arizona'

SELECT @OrgTimezoneOffset3 = -420

SELECT @OrgTimezoneOffset1, @OrgTimezoneOffset2, @OrgTimezoneOffset3

--Scenario #1: INT variable, assigned from table query - works

--Scenario #2: SMALLINT variable, assigned from table query - fails

Active Directory Issue : Validation fails for newusers and few randon users


Hi All,

We started observing this behaviour from past couple of days. Even the AD Validation fails for the newly created users. So there are few users for whom the Active Directory authentication fails. We are not sure why it is happening. The code and configuration is not a problem since the same code works for other environment which has different domains. Has some one seen this kind of behaviour before. Infact we had a service to authenticate users so initial culprit was the service but now we have minimize the problem domain to AD. I created a simple application which JUST VALIDATES the user against the AD but still the same problem.  I am getting very generic error which does not seem to help in debugging.

Any help will be highly appreciated.

Event Type:   Information

Event Source: ASP.NET 2.0.50727.0

Event Category:       Web Event

Event ID:       1315

Date:            4/5/2011

Time:            3:35:42 PM

User:            N/A

Computer:     TRNMCS001


Event code: 4006

Event message: Membership credential verifi

MS SQL Server: Disconnect Users From Database - Kill User Session

If you ever wanted to restore your database from a SQL backup file (.bak), but there are still users connected to your database, the backup operation will fail causing the error: Exclusive access could not be obtained because the database is in use.

Enabling Users to Maintain SharePoint Content

When SharePoint is installed as a corporate intranet, there is a considerable amount of effort involved in maintaining the content to keep the site relevant. As we discussed in the first few parts of this series, SharePoint has many built-in features to reduce the burden on the site administrator.

Some areas of the site usually contain less-dynamic information. Internal memos and corporate policies are common examples of this information. One option for this information is to post these documents in a document library. Documents in a library are often stored in a few different formats: Word, Acrobat (PDF), or HTML. Each of these formats has its drawbacks.

Enabling Users to Maintain SharePoint Content

When SharePoint is installed as a corporate intranet, there is a considerable amount of effort involved in maintaining the content to keep the site relevant. As we discussed in the first few parts of this series, SharePoint has many built-in features to reduce the burden on the site administrator.

Reading and Writing Images From a Windows Mobile Database using UltraLite 10(C#)

Periodically I get a request for information on how to read and write binary data to a database running on Windows Mobile. If you search the Internet you can typically find examples that are available on Windows Desktops or allow you to read and write to a local file system. The problem is that it can take a bit of work to get this code to work on Windows Mobile accessing a database.

Ultimately you might be asking, why would I want to store and image in a database? Well in an environment where you synchronizing data between a local mobile database and a consolidated (central) database this can be extremely useful. Imagine if an insurance adjuster went to an accident scene, took a picture of a damaged car, loaded it into his Windows Mobile database and then replicated that image up to the Insurance headquarters for approval. All of this could be done in a very short period of time when using images in the database. Another good example might be a doctor who was waiting for a patient chart to become available. If you could store the image in a database this chart could be sent down to the doctor's device once it became available.

For this article I am not going to get into how to synchronize the images to and from a remote and central database as this is typically fairly straightforward when using a data synchronization technologies like MobiLink

XML Reading and Writing

We learned to process XML files using the Document Object Model as implemented by the XmlDocument class. To go further and make XML friendlier, the .NET Framework provides many other classes for different purposes, allowing you to create and manage nodes from custom .NET classes.
Besides the XmlDocument and the derived classes of XmlNode, the .NET Framework provides the XmlTextWriter class, which is derived from XmlWriter. The XmlTextWriter class works in a top-down approach to create, or deal with, the contents of an XML file. This class writes an XML node and moves down without referring

Need help redirecting users to personalized page


 Hi, first timer here so be gentle.


I've been able to create a cool little website, it's up and running with users logging in and out, I created roles so my administrative team can see sensitive data that's not available to regular and anonymous users.

Now they would like me to create a page specific to each user.  For instance when user A logs in they are redirected to a page that has information that pertains to user A only (like a list of their benefits/ their remaining vacation time). This page needs to be accessible only to user A. 

I've watched a ton of the videos but have yet to see one that covers this topic, any help would be great!!!





Intranet Users Challenged When Using Windows Integrated Security


We've setup an intranet site using Windows Integrated Security. Its up and running and users can access it. However, they are being challenged with a login dialog for the server when they initially access the site.

Isn't is possible to configure the server so that the users aren't challenged AND are recognized as being already authenticated by Windows? We're trying to go with a seamless experience, whereby all they have to do is login to their machine like normal and then go from there.

Users getting logged out because HttpContext.Current is null


We've  been trying to fix this one for a couple years, and I'm just out of ideas, so any help is really appreciated!

We've got a fairly large, complex web application that uses Forms Authentication to authenticate users.  Throughout the application we store and retrieve information about users in the Session object, and in some cases in cookies.  In a couple places we check for the existence of the context, and if it's null we send the user back to the login page to re-establish the session. 

Just a quick run-down of this web app: C#, .NET 3.5, IIS 6, ASP.NET State Service to manage session

As for the session timer, we use our own home-grown timer, which is basically a client-side timer, which is backed up by a check to the SQL database to see when their last activity was.  This seems to work well for us.  It's not perfect, but it allows us to notify the user before the session times out, and allows us to be certain we're not logging a user out before their 60 minutes of inactivity is up.

What's happening is that certain users are being logged out after just a few minutes.  We've eliminated the timer as a cause and believe what's happening is the HttpContext.Current is null, so the user is logged out.  We do not know why the HttpContext.Current is null, and I underst

reading values from config files in NUnit tests


One of my NUnit tests has to read in some values from config files.  In my main application this process works perfectly well, however when I run the unit test, the code that reads in the values from the config files doesnt read anything in.  Ive tried putting app.config in my unit test project (I even tried web.config) but nothing seems to work.  Are there any special steps involved when reading from config files in an nunit test ?

Getting users list reporting to manager from LDAP


Dear All,

I need to get list of users reporting to a particular manager from the Active directory.

In the active directory there is manager property with contains the data in the following way.


Please help me in building the filter condition.

I am using the following

pUserName="Gegore Lid";

strSearch = "(&(objectClass=user)(objectCategory=user)((Manager cn=" + pUserName + "))";

DirectorySearcher dSearcher = new DirectorySearcher(dEntry, strSearch);

            //Account properites to load
            string[] arrPropertiesToLoad = { "displayName", "department", "manager", "sAMAccountName", "EmployeeNumber", "Title" };

          SearchResultCollection sResultColl = dSearcher.FindAll();

 the above code is not returning any result.

Please help me in this.



Use Membership but bypass / disable password usage for users


I have an application that does LDAP authentication. The authentication is done on the code behind page of my Login.aspx page. Once the user passes LDAP authentication, a cookie is set and I redirect:

FormsAuthentication.RedirectFromLoginPage(UserName.Text, False)

I would like to setup membership in my application and keep track of some user information. But due to company security requirements, I cannot store user passwords on my application. That must stay on the LDAP server only.

Is there a way to store users but disable password storage on the aspnet_membership table?

Getting list of users reporting from specific Manager from Active Directory


Dear All,

I am have requirement like displaying all the user information reporting to specific manager from Active Directory.

Please help me regarding this.



Reading data from .doc or .docx and inserting into db



A vendor is providing content which needs to be inserted into the db. The content is basically questions with options and explanations. An example is below.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend