|
Hi,
I use the Stream class in a framework.dll to read and write a setting like this,
get
{
Stream stream = GetStreamForRead(ClientHelpFile);
if (stream == null)
return HelpOption.Automatic;
int HelpOptionRead = stream.ReadByte();
stream.Close();
}
set
{
Stream stream = GetStreamForWrite(ClientHelpFile);
stream.WriteByte((byte)value);
stream.Close();
}
private const string ClientHelpFile = "TAC.ClientHelpProfile.bin";
private const IsolatedStorageScope scope =
IsolatedStorageScope.Roaming |
IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain;
private static IsolatedStorageFile GetIsolatedStore()
{
return IsolatedStorageFile.GetStore(scope, null, null);
}
private static Stream GetStreamForWrite(string filename)
{
IsolatedStorageFile storage = GetIsolatedStore();
return new IsolatedStorageFileStream(filename, FileMode.Create, storage);
}
private static Stream GetStreamForRead(string filename)
{
IsolatedStorageFile storage = GetIsolatedStore();
if (storage.GetFileNames(filename).Length == 0)
return null;
return new IsolatedStorageFileStream(filename, FileMode.OpenOrCreate, storage);
}
the problem I am facing is I am using another application and referencing the same dll(FrameWork.dll).
the storage.GetFileNames returns null and I wish it return me whatever the file has saved in it. Am I missing something?
|
|
|
|
|
AnilUnni wrote: the problem I am facing is I am using another application and referencing the same dll(FrameWork.dll).
the storage.GetFileNames returns null and I wish it return me whatever the file has saved in it. Am I missing something?
I think, note that is bold, that the problem might be IsolatedStorageScope.Domain . Each application runs in its own domain, so the path to the isolated storage will be different from different applications.
Once again, this is not a certainty, just my interpretation of how it works.
If it were my app, I would start with just IsolatedStorageScope.User, see if it works for both apps add another scope see if it works etc until it fails. That way you will identify which scope(s) will break it and can avoid them.
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 all,
Thanks a lot for your help in advance.
I am doing a Mail Merging Application. I can get all data from the source (database, file or anything) and using mail Merge fields in Word Document from C# code, I open up the word which is merged with data from database.
MS Word Document Opens –
--- should this be open in IE
--- Or should this be open as ordinary MS Word on Desktop
The problem is if I open it anyway, I loose all control over the Word Document which is opened. I don’t want to do that. I want to keep control over it and allow the Users to update the document with some standard messages which we have in the project. What that means is, the messages will be selected and those messages selected will be put at some point where cursor is kept in the document.
So, when mail merging happens
MS Word Document is opened.
A pop up with standard messages is opened.
User selects the messages he/ she wants to insert into the MS Word Document which is opened.
For these things to happen, I should have control over the MS Word Document which is opened on the client side. Do selection of the messages and populate in Word document (this is my understanding, is there any way to do it easily).
The Issues are:
I need a way to open the MS Word Document in a controlled manner where I can still control the User editing or help user in editing when he / she clicks on my standard messages and wants them to populate on the MS Word Document.
How can I save the MS Word document and make sure that user is not saving it locally and has to upload it again to save it on server.
I Hope I am clear in explaining the situation, please find the attachments which show the MS Word Doc and the popup on side .
ANY RUNNING CODE WILL BE OF GREAT HELP.
|
|
|
|
|
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.
|
|
|
|