How to send email with saved file

cp713a

Member
Joined
Jul 26, 2022
Messages
7
Programming Experience
Beginner
I need some guidance on how to call, invoke or execute when I have a file saved from this:
using (TextWriter fn = new StreamWriter(outputDirectory + "\\SomeName" + DateTime.Now.ToString() + ".csv")). ...etc so a file will be generated like this: SomeName08/01/2022: 12:00:00.csv. I want to be able toinclude this variable fn as a file attachment to be sent out to email recipients.

Any idea on how to achive this?
 
So far, all your questions look like they are related to your job. Have you taken time to talk to your manager to tell them that you need more guidance on how to do the tasks assigned to you? Right now, it feels like we are doing your job for you.
 
Better question is the fn variable is inside the main program like this:
C#:
    static void Main(string[] args)
    {  some variables;
       some variables;
       some variables;
using (TextWriter fn = new StreamWriter(outputDirectory + "\\SomeName" + DateTime.Now.ToString() + ".csv"))
{
  calculations....
fn.WriteLine("Something here NOT important");
}
and here I need to know how to invoke the variable fn, because when I did it says the name 'fn' doesn't exist in the current context. I just wanted to know what I needed to do so that I can attach the fn variable as part of my mail?

Any ideas?
 
Last edited by a moderator:
Yes. Read about the using statement, and recall how scope works in C#.


Basically, you can't do it with the way your code currently stands.
 
Even if you did successfully get the StreamWriter instance, how is that going to help you considering that the MailAttachment doesn't have a constructor that takes a StreamWriter?
 
Even if you did successfully get the StreamWriter instance, how is that going to help you considering that the MailAttachment doesn't have a constructor that takes a StreamWriter?
if I have known, would I be still asking? BTW, if you want to insult, look down on other people who are less experience, I wonder what else are you good at?
 
Last edited:
Apparently I'm also good at insulting people when all I was doing was just stating a fact. I guess it is better to just let people fail on their own instead of warning them that they are headed down a deadend.
 
Back
Top Bottom