Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:42:23+00:00 2026-06-09T18:42:23+00:00

I want to send a file via email using c# ASP.net (Maybe more files

  • 0

I want to send a file via email using c# ASP.net (Maybe more files too, but for the moment I’m concerned about sending at least only one file)

For the moment, I do have a method that does work if you want to send an Email

public string EnviarMensaje(int intIdVendedor, string strCorreoPara, string strCorreosAdicionales, string strTema, string strMensaje, string strRuta)
    {
        string strResultado="";
        DataTable dt = ConexionBD.GetInstanciaConexionBD().GetVendedorEspecifico(intIdVendedor);
        string strCuerpo = strMensaje + "\n\n\n\nMensaje Enviado Por:\n" + dt.Rows[0]["Vendedor"] + "\n" + dt.Rows[0]["Email"] + "\n" + dt.Rows[0]["Telefono"];
        string[] strListaCorreos = strCorreosAdicionales.Split(new Char[] {' ', ','}, StringSplitOptions.RemoveEmptyEntries);

        try
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtpout.secureserver.net");

            mail.Subject = strTema;
            mail.Body = strCuerpo;
            mail.From = new MailAddress(strCorreoDe);
            mail.To.Add(strCorreoPara);

            foreach (string c in strListaCorreos)
            {
                mail.To.Add(c);
            }

            if (strRuta != "")
            {
                Attachment attachment;
                attachment = new Attachment(strRuta);
                mail.Attachments.Add(attachment);
            }

            SmtpServer.Port = 80;
            SmtpServer.Credentials = new System.Net.NetworkCredential(strCorreoDe, strContrasena);
            SmtpServer.EnableSsl = false;

            SmtpServer.Send(mail);
            strResultado = "Exito";
        }

        catch (Exception ex)
        {
            strResultado = ex.ToString();
        }

        return strResultado;
    }

in aspx I have

<asp:FileUpload ID="fileUploadArchivos" runat="server" />

<asp:ImageButton ID="imgBtnEnviar" runat="server" Height="60px" Width="60px" ImageUrl="~/img/iconos/email.png" CausesValidation = "True" ValidationGroup="vgpCorreo" onclick="imgBtnEnviar_Click" />

and on the cs I have

EnviarEmail objEmail = new EnviarEmail();

protected void imgBtnEnviar_Click(object sender, ImageClickEventArgs e)
{
if (fileUploadArchivos.HasFile)
{
    strArchivo = Path.GetTempFileName();\\RIGHT NOW I LEFT IT THIS WAY, BUT I NOW THAT HERE IS THE PROBLEM, I DON'T KNOW WHTAT CAN I DO HERE
}
string strResultado = objEmail.EnviarMensaje((int)Session["IdVendedor"], lblCorreoPara.Text, tbxCorreoPara.Text, tbxTema.Text, tbxMensaje.Text, strArchivo);

}

However, the problem is in a FileUpload.
I have tried many methods like, Server.MapPath, Path.GetFileName, GetDirectoryName, GetFullPath, GetPathRoot… and I’m always getting either nothing, only the filename or a completely different path (I guess is a server kind of path)..

I only for the moment want to get a file path as simple as C:\Test.txt for example…
I suppose that if I can get that exact string from the FileUpload, I’ll be able to send it… However, I can’t figure out how to make it work.

Hope you can help me
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:42:24+00:00Added an answer on June 9, 2026 at 6:42 pm

    If you need a local copy of the file uploaded kept on the server you can just do

    fuFileUpload.SaveAs(MapPath(filepath));
    

    Then your strRuta can use the file you just saved via

    strRuta = Server.MapPath(filepath);
    

    ready to pass into the new Attachment object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a test.html file that I want to send via email(I am refering
I want to send someone a CHM file via email. When they receive the
I have to send HTML file via email but not as attachment. Message simpleMessage
i want to send a .doc file as an attachment via email. i am
I want to send more than one image file from client to server for
In my app, i want to send a file to another iOS device via
At application shutdown I want to send a file to a server via Internet
Trying to upload files using Google Gears and ASP.NET... I assume you can as
i have a form that contains 3 File inputs.i want to send it via
I want to send a file to the Browser via the REST Interface. Can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.