|
Problem occurs when I exit out of the application.
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
Whatever has been written to my config file and saved to the file
goes back to what it used to before.
I have no idea why ? Do you guys have any idea?
System.Configuration.Configuration config = null;
config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add(strJob, strValue);
config.Save();
|
|
|
|
|
Your asking for information that applies to all users, by specifying ConfigurationUserLevel.None . Not a per user level, which is what your trying to save.
Try the other types.
Also settings should be user level and not application level. Or they'll never change anyway.
Using the wrong tool for the job is half the fun.
|
|
|
|
|
Tried
config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming);
crashed at Config.Save.
|
|
|
|
|
Hey all
Does anybody experience flickering of the desktop icons, application window icons (any open application) whilst visual studio c# express is running? like for example i'll go to debug and then if i open a context menu or do anything in my program everything on my computer starts to flicker. Desktop icons, icons inside programs, and other controls such as comboboxes buttons etc? I don't have any viruses/trojans or anything like that so I'm puzzled. And it only just started happening. I've never had this problem before, I do remember though reading on here a while ago about someone who had the same problem but don't remember any solutions or anything...
jase.
|
|
|
|
|
i have a program that authenticated users with Active directory how do i query AD to find out when is the last time a user was authenicated i trided using last logon time but this is only updated when they log on to the computer not when the authenticate
|
|
|
|
|
lastlogon is notorious in fact it doesn't even replicate if you have more than one DC. Try lastlogontimestamp. However this only works with 2003 server and above, and they have to be in the correct 2003 Domain mode. No 2000 servers.
Otherwise it's lastlogon and checking all the servers. and even then it might not be accurate.
Using the wrong tool for the job is half the fun.
|
|
|
|
|
Login Using Active Directory Services (ADS)
In order to use SDS, first we have to set properties of LDAP server. Here database ADSI_PARAMETER table is used to set the LDAP properties.
CREATE TABLE [dbo].[ADSI_PARAMETER] (
[ParameterName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[ParameterValue] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
Enter following data to table in ParameterName and ParameterValue fields
Parameter Name ParameterValue
ServerName WindowsDomainServer
BaseDN DC=DomainName,DC=COM
UserDN OU=Users
GroupName CN=Operater, OU=Groups
AccountFilter sAMAccountName
Where ServerName is your domain server machine name. BaseDN is your domain name, most of the time it is company name. UserDN is organizational unit where user should exist. GroupName is organizational unit, to which user should belong in order to access your software. AccountFilter is filter for account name; mostly it is sAMAccountName in windows.
Code for GetADSILogin function.
public void GetADSILogin()
{
try
{
string strServerName = "";
string strBaseDN = "" ;
string strUserDN = "";
string strGroupName = "";
string strAccountFilter = "";
//Port no for LDAP Default is 389
string strPortNo = "389";
Boolean blnGroupUser=false;
//Data source string
string source = "Data Source=ATHAKUR;Initial Catalog=Times;user=sa;password=sa" ;
//SQL statement that will be issued
string select = "SELECT * from ADSI_PARAMETER";
//SQL Connection
SqlConnection conn=new SqlConnection(source);
// Open the database connection
conn.Open () ;
// Create the SQL command...
SqlCommand cmd = new SqlCommand ( select , conn ) ;
//Execute Data reader
SqlDataReader myReader = cmd.ExecuteReader();
//Check if any rows return against user/pass
if(myReader.HasRows)
{
while(myReader.Read())
{
//Store the parameter's data in variables
string strParameterName = myReader.GetString(0).Trim();
string strParameterValue = myReader.GetString(1).Trim();
if(strParameterName.ToUpper().Equals("SERVERNAME"))
strServerName=strParameterValue;
if(strParameterName.ToUpper().Equals("BASEDN"))
strBaseDN=strParameterValue;
if(strParameterName.ToUpper().Equals("USERDN"))
strUserDN=strParameterValue;
if(strParameterName.ToUpper().Equals("GROUPNAME"))
strGroupName=strParameterValue;
if(strParameterName.ToUpper().Equals("ACCOUNTFILTER"))
strAccountFilter=strParameterValue;
}
}
//Search for user
DirectoryEntry deSystem = new DirectoryEntry("LDAP://" + strServerName + "/" + strUserDN + ","
+ strBaseDN);
deSystem.AuthenticationType=AuthenticationTypes.Secure;
deSystem.Username=txtUserName.Text;
deSystem.Password =txtPassword.Text;
//Search for account name
string strSearch=strAccountFilter + "=" + txtUserName.Text;
DirectorySearcher dsSystem = new DirectorySearcher(deSystem,strSearch);
//Search subtree of UserDN
dsSystem.SearchScope= SearchScope.Subtree;
//Find the user data
SearchResult srSystem = dsSystem.FindOne();
//Pick up the user group belong to
ResultPropertyValueCollection valcol = srSystem.Properties["memberOf"];
if(valcol.Count>0)
{
foreach( object o in valcol )
{
//check user exist in Group we are searching for
if(o.ToString().Equals(strGroupName+","+strBaseDN))
{
blnGroupUser=true;
break;
}
}
}
if(blnGroupUser==true)
MessageBox.Show("Login Sucessfull...");
else
MessageBox.Show("User Does Not Belong to Specified ADSI Group");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
i=i+1;
if(i==5)
{
MessageBox.Show("Login failed for 5 times. Quiting...");
this.Close();
}
}
If everything works fine then you will get the message "Login Successful". If user does not belong to group specified in LDAP properties then will the message "User Does Not Belong to Specified ADSI Group". If you enter wrong user/pass, you will get Logon failure message.
|
|
|
|
|
That's alot of work and a complete waste considering you didn't even the the OP's question...
|
|
|
|
|
Heres what I do now
Type a = b.GetType();
if (a.Name == "Blog")
{
Console.WriteLine("blog = {0}", ((Blog)b).text);
error = "ok";
return 0;
}
if (a.Name == "String")
{
Console.WriteLine("blog = {0}", (String)b);
error = "ok";
return 0;
}
Console.WriteLine("blog = TypeError");
error = "unKnownType";
return 1;
I want to set the type similar to this
((GetType())b).text
How can I do this ?
|
|
|
|
|
If b implements the interface IBlog, then you can cast b to an IBlog and provided Text is part of the interface declaration and is implemented in b's class, you can get the text. Something like:
interface IBlog
{
public string text { get; }
}
public class Blog : IBlog
{
public string text
{
get { return "name"; }
}
}
public int testThisExample()
{
object b = new Blog();
if(b is IBlog)
Console.WriteLine("blog = {0}", (b as IBlog).text);
return 0;
}
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
You could override the ToString() function in the Blog class.
class Program
{
static void Main( string[] args )
{
object obj = "Test from string";
Console.WriteLine("The result of to string is:" + obj.ToString());
obj = new Test();
Console.WriteLine("The result of to string is:" + obj.ToString());
Console.ReadKey();
}
}
public class Test
{
public override string ToString()
{
return "Test from class";
}
}
Using the wrong tool for the job is half the fun.
|
|
|
|
|
Hi,
1.
you could concentrate on the ToString() method which exists for all objects; you should override for most types since for most classes ToString() by default returns a type string.
2.
you should NOT check types by getting the type's name, then string.compare.
C# has the is keyword which returns true when the type matches (directly or through inheritance).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi All,
I'm pretty new here so excuse my ignorance
I've just started learning C# and come from a long history of C/C++/PowerBASIC/Assembly, 20 years total.
To learn C# I decided to jump in with both feet and recreate some past projects for fun. So here is what I want to do and where I am getting stuck.
I have a Layout which consists of Tracks, each Track contains Layers. Think of this like an multi-track audio application and Photoshop combined.
Each Track in a Layout should have a unique Name. Every Layer in a Track should also have a unique Name. This sounds to me like I need to use a Dictionary collection. I also need to iterate over these Tracks and Layers in order to draw them IN the correct order. The order should be user defined and should allow for user re-ordering (MoveUp MoveDown type of thing).
So I'm left thinking I need a Dictionary + Sorted Array by Order collection?
I'm sure this can be done but as I said I'm quite new to C#/.NET and would like some direction.
Thanks!
|
|
|
|
|
A Dictionary might be the way to go, but you will have to be very careful what you use for the key. If you use trackName it will complicate retrieving the display order. Even if you use displayIndex, implementing the move up/down functionality could get complicated.
Without thinking about it for a while, I don't have a better suggestion, but I'm sure that somebody will.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
If by user defined, you just mean the user can reorder them manually, then just a dictionary works fine to create mappings of Tracks to Layers. I thought that the order of keys remains the order in which they were added, also, although I am not sure that the collection supports remove at index and add at index, I would have to hope that it did.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
You can use queries with orderby clause - then you can have your displayOrder as a part of your Track schema and make sequence ordering by this parameter while maintaining Dictionary capability.
|
|
|
|
|
Just want to say thanks for the advise so far. You've given me some more things to think about and try. I'm going to spend today tinkering again and might post some code later for further advise.
|
|
|
|
|
Ok guys,
Looks like I've gone a thoroughly confused myself here. Perhaps one of you kind folks can chime in and set me straight.
Here are my requirements:
1. Collection of layers called layerCollection
2. Each Layer must have a Name property that is unique to the collection it resides in.
3. You can access each Layer in the collection by Name or Index[]
foundLayer = layerCollection.getLayer("Background"); <-- returns Layer with layerName = "Border"
foundLayer = layerCollection.getLayer("Border");
foundLayer = layerCollection [0];
foundLayer = layerCollection [1];
etc...
Help
Once I figure this part out I'm sure sorting the layerCollection to reorder them will be a simple task.
Thanks again for your help and patience!
|
|
|
|
|
|
Impossible. It has nothing to do with .NET, it has to do with how your PC processes sound. That's precisely what DirectX is for.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
my code is as follow. I need to fig out a way to handle if results dosnt find any thing sshow yes something was found or no users had been found at this time. Iv tried to fig this out but im unable to do so. Thank you for your time.
DateTime dt = DateTime.Today;
DateTime less5dt = dt.AddDays(-5);
This.cmb1.Items.Clear();
PrincipalSearchResult<UserPrincipal> results =
UserPrincipal.FindByLockoutTime(
adPrincipalContext,
dt,
MatchType.GreaterThanOrEquals);
foreach (Principal result in results)
{
cmb1.Items.Add(result.name);
}
|
|
|
|
|
You don't even have an if statement, so what's the problem with it?
What in this code is a "user"?
Is every result in results a user?
|
|
|
|
|
harold aptroot wrote: You don't even have an if statement, so what's the problem with it?
What in this code is a "user"?
Is every result in results a user?
The users that are locked out in Active directory then it populates them in a cmb1
just want a statement to allow me to show a message to the user yes something was found or now nothing was found. and im unable to fig that out.
|
|
|
|
|
Hi,
bool someUsersWereFound = results.Count!=0;
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
modified on Wednesday, June 10, 2009 1:48 PM
|
|
|
|
|
Luc Pattyn wrote: Hi,
bool someUsersWereFound = results.Count!=0;
Smile
first off THANK YOU !
sorry for the noobieness how would I incorporate this into my code?
|
|
|
|