user2777546
user2777546

Reputation: 127

File upload working on localhost but not godaddy server (dnn website)

I have created a module that send email with attachment locally it works fine but on the webserver(godaddy) it doesn't work. I got this error.

A critical error has occurred. Empty path name is not legal.

private void SendEmailNotification2()
{
    string to = "[email protected]";
    string from = "[email protected]";
    string subject = "CV from Web Site";
    string body = "New CV from Web Site";

    using (MailMessage mm = newMailMessage(txtEmail.Text, "[email protected]"))
    {
        mm.Subject = "ssss";
        mm.Body = "baaa";
        if (FileUpload1.HasFile)
        {
            string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
            mm.Attachments.Add(newAttachment(FileUpload1.PostedFile.InputStream, FileName));
        }

        mm.IsBodyHtml = false;
        SmtpClient smtp = newSmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { returntrue; };
        NetworkCredential NetworkCred = newNetworkCredential("[email protected]", "Password");
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587;
        smtp.Send(mm);
        // ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
    }
}

Upvotes: 0

Views: 406

Answers (1)

Manish Dalal
Manish Dalal

Reputation: 1796

Are you able to upload the file on the server? By default the shared space on GoDaddy server do not allow file upload (your folder do not have write permission by default)

Note: I would have added this as a comment to the question, but as I cannot post comments as of now, so writing this in an answer.


Glad to help! Please remember to accept the answer if you found it helpful.

Upvotes: 1

Related Questions