|
Sandumone wrote: ANY RUNNING CODE WILL BE OF GREAT HELP.
So this is a new way to say snd me the codz. This will get you flamed severely for being rude and shouting it is just plain stupid.
You have a design problem, why do you open the word document before asking the user for the message. Get the message text in your app before you start the word merge that way you do not need to relinquish control.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I need to get the full name and email of a user using nothing more than the 2.0 Framework.
I figured LDAP would be the best way to go, but I cannot get my code to work.
I am not using the syntax correctly. I need to get the information using the logged in user name.
if my username is "mypicturefaded" and my email for the company is mypicturefaded@bbt.gov, how would I get the full name or email address. Is there an easier way of doing this? It needs to be from Active Directory though. I can do it using 3.5 framework, but it needs to be rolled back. Here is the code I have:
<br />
<br />
string strValue;<br />
DirectoryEntry ent = new DirectoryEntry("LDAP://CN=mypicturefaded");<br />
strValue = ent.Properties["displayName"].Value.ToString();<br />
ent.Close();<br />
<br />
Messagebox.Show(strValue);<br />
<br />
|
|
|
|
|
|
Here [^]you go.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
So how come something like this doesn't work?
<br />
<br />
DirectoryEntry entry = new DirectoryEntry("LDAP://DC=bbt,DC=com");<br />
DirectorySearcher mySearcher = new DirectorySearcher(entry);<br />
mySearcher.Filter = "(&(objectClass=user)(anr=" + "mypicturefaded" + "))";<br />
SearchResult searchResult = mySearcher.FindOne();<br />
string email = searchResult.Properties["mail"].ToString();<br />
MessageBox.Show(email);<br />
I just need the one field. I really don't need all of them.
I get a NullObjectException error.
|
|
|
|
|
Should be like this:
DirectoryEntry entry = new DirectoryEntry("LDAP://DC=Domain,DC=com");
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(&(objectClass=user)(anr="+ userID +"))";
mySearcher.PropertiesToLoad.Add("mail");
SearchResult searchResult = mySearcher.FindOne();
string email = searchResult.Properties["mail"];;
MessageBox.Show(email);
You did not add mail as a property to be loaded.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
"A referral was returned from the server." is the error I am getting now.
Hmmm, this is more tricky than I thought.
|
|
|
|
|
username should always be specified as domain\username. Maybe that's the problem?
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I did it that way. It still isn't working though...Thank you for your help though.
It was a step in the right direction at least. So thank you. What does the anr stand for?
Here is the 3.5 code I am using.
<br />
email = System.DirectoryServices.AccountManagement.UserPrincipal.Current.EmailAddress;<br />
Too bad I can't just use it.
|
|
|
|
|
|
Hi all,
I am having problems passing a method from form 1 to form 2. I have on form 1 a dgv and a button. When the form 1 button is clicked it takes me to form 2. On form 2 I have the same set up, a dgv and a button. However, the button on Form 2, when clicked should call a method from form 1 then closes form 2. When I run the windows form application I get no errors. The method on form 1 that I try to call from form 2 is public. Any help is much appreciated. Thank you!
Code:
Form 1
public void UpdateGridView()
{
// Method code
}
form 2
public void MapFormUpdate_Click(object sender, EventArgs e)
{
Form1 MainForm = new Form1();
MainForm.UpdateGridView();
this.Close();
}
|
|
|
|
|
You made a new form to call a method on and then throw it away. I would advice you not to ask why that does not do what you want, I'm sure several people will laugh at you and/or 1-vote you.
|
|
|
|
|
I tried it without the Form1 MainForm = new Form1(); code but it gives an error NullReferenceException. How can I get around this?
|
|
|
|
|
You want to call it on the original form, not a new one. Usually you only have 1 instance of the main form anyway, so you could use the singleton pattern (makes managers and Java programmers happy) or just pass the instance of form1 to form2 when you make form2. (or use an event, see Davey's post)
There is a difference between a class and an instance of it. I'm sure you know, but it seems like you need to be reminded of that. But no offense..
|
|
|
|
|
No offense taken. I'm new to C# programming. Usually work with SQL. Thanks for the input!
|
|
|
|
|
Form1 MainForm = new Form1(); is not going to work as it's a new instance of Form1, not the one that you started with.
The recommended way of doing this is to raise a custom event in form2, that Form1 subscribes to, so Form1 calls its own method.
using System;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonShowForm2_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.DoUpdate += new EventHandler(form2_DoUpdate);
form2.Show();
}
void form2_DoUpdate(object sender, EventArgs e)
{
Console.Write("Update");
}
}
using System;
using System.Windows.Forms;
public partial class Form2 : Form
{
public event EventHandler DoUpdate;
public Form2()
{
InitializeComponent();
}
void buttonUpdate_Click(object sender, EventArgs e)
{
OnDoUpdate(EventArgs.Empty);
}
protected virtual void OnDoUpdate(EventArgs e)
{
EventHandler eh = DoUpdate;
if (eh != null)
eh(this, e);
Close();
}
} If you need to pass data along with the event, create your own class derived from EventArgs and pass an instance of that instead of EventArgs.Empty. You will need to change the EventHandler to EventHandler<YourEventArgs>
See my Events Made Simple[^] article for more details.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thank you for your reply. That works perfectly.
|
|
|
|
|
Hej bwood2020
You Migth whant to use a static resource that can laungh that form1 passes an event to
static class EventHandler
{
static Action Event;
public static void SetGlobalEvent(Action a)
{
Event = a;
}
public static void Execute_Event()
{
Event();
}
}
class Form1
{
public Form1()
{
EventHandler.SetGlobalEvent(Event);
}
public void Event()
{
var x = 2 + 2;
}
}
class Form2
{
public void Onclick()
{
EventHandler.Execute_Event();
this.Destroy();
}
}
There migth be a bether way of doing this if form1 creates form2 you can pass
in "this" from form1 as a parameter that way form2 whill be able to call the method on that object
Hopes this helps Patrik
|
|
|
|
|
Patrik.karlin wrote: if form1 creates form2 you can pass
in "this" from form1 as a parameter
... but now you're starting to couple unrelated classes - not a great idea. The easiest, sure - but best avoided.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
DaveyM69 wrote: ... but now you're starting to couple unrelated classes - not a great idea. The easiest, sure - but best avoided.
.... Yea Sure .. maybe the logic should be in the model....
form1 can subscribe to a datachanged event and form2 youst update's the
data in the model...
then they whill be completle seperated.
|
|
|
|
|
Does this look at all familiar? clickety[^]
[Edit]
Sorry wrong link! Try this one. here[^]
[/Edit]
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.”
|
|
|
|
|
Hi Henry,
It does and I tried to aply the same logic but it wasn't working. The code I used to get this to work was differnt. I think it had to do with adding another event handler to take care of it.
|
|
|
|
|
|
You're looking for the ASP.NET forum. What you asked has nothing to do with C#.
|
|
|
|
|
Dave Kreskowiak wrote: You're looking for the ASP.NET forum
Ftfy, Web Development
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|