|
No, you need to covert it back to MemoryStream.
MemoryStream ms = new MemoryStream(myReport);
em.Attachments.Add(new Attachment(ms, [your mime type]));
modified 17-Jul-19 21:02pm.
|
|
|
|
|
ok, thanks for the postings, I could not get it done since I am not using .NET 2
in older version it just accepts the file path, but new one gets the MemoryStream too.
|
|
|
|
|
I would like to create a handler for form.GotFocus(). In VB I would use a procedure created by the IDE:
vb:
Private Sub Form1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
DOIT()
End Sub
How is this reflected in c#?
private void Form1_GotFocus(object sender, EventArgs e)
{
}
Jon
|
|
|
|
|
that seems correct. just add "DOIT();" to the methods body.
What is the problem?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
the problem was finding the command that tells .NET which function handles which event; I had second thoughts and used the EventHandler.
Jon
|
|
|
|
|
OK, I see; as Christian already replied, you add a delegate to the Focus event:
this.Focus+=new EventHandler(Form1_GotFocus);
the nice thing about Visual Studio C# is as soon as you enter the +=
it suggests the remainder of the line; tab twice to accept and automatically
get the handler's skeleton.
Alternatively you can do the same thru Visual Designer (if so, the this.Focus+=
line will appear file in Form1.Designer.cs)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
You can do it in the designer, or you can put some code somewhere that says this.Focus += new EventHandler(this.Form1_GotFocus); Something like that.
Yes, I like how VB does it.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi
I want to create an application that reads the videostream from a webcam, alter the videostream by applying filters, and send the altered stream to an application (like MSN, Skype and other apps that can use cams). To get this to work I guess I have to create an app that reads data from my default webcam, alter the videostream and sends this to a webcam driver that I have created.
In order to let MSN view the altered videostream by default, I need windows to think it has an extra webcam. In MSN it is possible to choose from several cams, and if I can et my "fake" driver to appear in that list, I can send my altered videostream to that driver.
Is this the way to do it? And how can I make this driver? Do I need anything else than WDK?
I'll appreciate all help.
-Martin
|
|
|
|
|
Maybe this holds the key[^]
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
thanx for the reply, but I didn't find what I'm looking for.
Instead, anyone who can tell me what I need in order to create a driver? Is WDK the only thing I need?
|
|
|
|
|
I am trying to create new "Communications cable connection between two computers"s in C# to be used with an existing or new Direct Connection (PPP link) in the RAS phone book. I have not been able to find any documentation on this and have been completely unsuccessful in figuring it out.
Any help would be GREATLY appreciated.
----------------------------------------------
Keith
|
|
|
|
|
KeithWT wrote: have been completely unsuccessful in figuring it out.
That's unfortunate.
KeithWT wrote: Any help would be GREATLY appreciated.
Read the first thread in this forum titled "How to get an answer to your question".
|
|
|
|
|
My initial posting was cryptic and so I will clarify it.
Windows RAS uses a "Communications cable between two computers" hardware object in the modem section of Device Manager, which is basically a virtual driver that lays on top of an existing serial or LPT port (like an external modem driver).
What I am trying to do is programmatically create or modify a "Communications cable between two computers" hardware object in the modem section of Device Manager. Exactly what I want to modify is the [Serial Port Number] and the [Baud Rate].
The Windows platform is WinXP Home/Professional, but I think that Win2K is exactly the same.
|
|
|
|
|
If you're using .Net 2.0 or above, look into using the "SerialPort" class. However, with .Net 1.x, you will have to look at using one of the serial port implementations that exist on this website.
Phil
|
|
|
|
|
When I rename the file that the code below is trying to open, I would expect an exception to be thrown(according to MSDN documentation). However, no exception is thrown and sr == null. Can anybody show me what I may be missing here?
StreamReader sr = null;
try
{
sr = File.OpenText(strFileName);
}
catch(System.IO.FileNotFoundException)
{
listBoxErrors.Items.Add("Unable to locate upload file.");
}
catch(Exception ex)
{
listBoxErrors.Items.Add("general error.");
}
Thanks,
Craig
Craig
|
|
|
|
|
You're not getting an exception because you are not trying to catch the correct exception. Using FileNotFoundException will throw an exception when a file you attempt to access doesn't exist. Replace your catch with the one below and it should work.
<br />
catch(FileNotFoundException ex)<br />
{<br />
listBoxErrors.Items.Add("general error.");<br />
}</
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
I am trying to catch the FileNotFoundException so I don't what your talking about. Look closer at my code sample. Have you ever tried this yourself. It seems to me that I should get a FileNotFoundException but that's not my experience.
Craig
|
|
|
|
|
No, I haven't tried this myself. Did you try using the code snippet I provided? Your are trying to catch a general Exception. No general exception is going to be produced if the file doesn't exist, you need to catch the FileNotFoundException.
I didn't actually read your code completely, but I thought I did. I tested the below code and it worked just fine.
System.IO.StreamReader sr = null;<br />
try<br />
{<br />
sr = System.IO.File.OpenText(@"C:\Data.txt");<br />
}<br />
catch (System.IO.FileNotFoundException)<br />
{<br />
MessageBox.Show("Unable to locate upload file.");<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show("general error.");<br />
}
-- modified at 16:28 Thursday 16th August, 2007
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
I see my mistake. I should have been returning after catching the exception. I was only reporting it and hence the procedure would continue and try to open up the file. But to correct your last statement "no general exception is going to be produced if the file doesn't exist, you need to catch the FileNotFoundException" this isn't true.
FileNotFoundException is the more specific exception and if a catch for this is not specified, the general exception would be caught. If you look at my code sample you will see that I was filtering down to the more general exception in case some other type of unknown exception occurred.
Thanks for taking the time to exchange some ideas. I spaced and I don't have any other software people here to bounce thoughts off of.
I need another cup of coffee,
Craig
Craig
|
|
|
|
|
Interestingly enough, I have just had the same issue that you were having. How did you correct for this?
CTaylor89 wrote: I should have been returning after catching the exception. I was only reporting it and hence the procedure would continue and try to open up the file.
I don't get what that means though
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
All I was trying to say was that in my exception handler I was only putting up a message box to report the exception. What I forgot to put in the exception handler was a return statement so that I would not continue executing in the current function trying to execute code that depended on the file being open.
Craig
|
|
|
|
|
Hi there,
More questions!!!
I need to know how I can obtain the number of files in a directory programmaticaally (including files in sub folders). Well, I can do this by getting the directory list, and recursively getting the file list in them and have a variable to increment. But, i wonder whether there is a more straightforward method.
Secondly, I need to know of a procedure to get the file size of a file through C# coding.
Regards,
A
|
|
|
|
|
The relevant classes are File, FileInfo, Directory, DirectoryInfo
they are fully explained in the MSDN documentation.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hey folks. Not sure if this belongs here but it seems to me it's more of a C# thing than an SQL thing.
I'm writing a reporting program for the high school I work for, to allow teachers to write reports with pre-defined statements. We already have one in place that's written with Access, but it's a PITA and needs replacing, hence me breaking out the C#.
Now I'm amateurish at best (I'm IT Support, not a programmer for starters), so lets get that out of the way!
I'm using Castle ActiveRecord to let me do ORM and handle my database for me. I have four Achievement tables and 3 Target tables and they all have the same layout (schema?) of (Id, Subject, Comment, YearGroup) - so we have tables in the db called Achieve1 - Achieve4, and Target1 - Target3.
Since each table has to be managed with a corresponding class for ActiveRecord, I created a base abstract class that the other tables could inherit from and initialise ActiveRecord against...
Wow, I'm explaining this crappily - here is some code instead to illustrate:
abstract class AchieveTargetBase : ActiveRecordBase
{
private int _id;
private Subject _subject;
private string _comment;
private int _yeargroup;
[PrimaryKey]
public int Id
{
get { return _id; }
set { _id = value; }
}
[BelongsTo("Subject")]
public Subject Subject
{
get { return _subject; }
set { _subject = value; }
}
[Property(Length=400)]
public string Comment
{
get { return _comment; }
set { _comment = value; }
}
[Property]
public int YearGroup
{
get { return _yeargroup; }
set { _yeargroup = value; }
}
}
And then I do...
[ActiveRecord("Achieve1")]
class Achievement1 : AchieveTargetBase
{
}
And so on, per table, which works fine.
Now the problem I have is with writing classes that I need to use on each table, because I need to reference the class itself. As an example, if I were to write code that retrieves the comment text of selected rows for Achieve1
[ActiveRecord("Achieve1")]
class Achievement1 : AchieveTargetBase
{
public static string[] GetListOfEntries(Subject subj, int year)
{
List<string> Entries = new List<string>();
foreach (Achievement1 x in (Achievement1[])ActiveRecordBase.FindAll(typeof(Achievement1), Expression.Eq("Subject", subj), Expression.Eq("YearGroup", year)))
{
Entries.Add(x.Comment);
}
string[] ret = Entries.ToArray();
Array.Sort(ret);
return ret;
}
}
I've tried replacing Achievement1 in the foreach argument with AchieveTargetBase and putting it into the AchieveTargetBase class instead but that just throws up an error (which I expected, to be honest).
Is there any way I can make methods like that apply for each class without having to write it separately for each of the derived classes?
Disclaimer: I'm a n00bish programmer. Please be gentle. (Especially if the answer is dead easy cos it'll just make me feel stupid.
-- modified at 6:02 Friday 17th August, 2007
|
|
|
|
|
Your base class does not need to be pure abstract, you can have common function in it that all derived classes can use.
only two letters away from being an asset
|
|
|
|