473,394 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

We have facing a problem when we upload a file using smtp in asp.net

When we run the application on localhost the attachment is upload succesfully and the mail is send.

But when we upload the site on webserver, and run the application the attachment was not uploaded because the attach file is not finding on web server.

Our code is

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Net.Mail;
  12. using System.IO;
  13.  
  14.  
  15. public partial class _Default : System.Web.UI.Page
  16. {
  17.     String filename;
  18.  
  19.     protected void Page_Load(object sender, EventArgs e)
  20.     {
  21.  
  22.     }
  23.  
  24.     protected void zSubmitBt_Click(object sender, EventArgs e)
  25.     {
  26.         try
  27.         {
  28.             MailMessage mail = new MailMessage();
  29.  
  30.             mail.To.Add ("tomailaddress.com");
  31.             mail.From = new MailAddress("frommailaddress.com");
  32.  
  33.             mail.Subject = "Resume";
  34.  
  35.             string ml;
  36.             if (zMaleRBt.Checked)
  37.                 ml = zMaleRBt.Text;
  38.             else
  39.                 ml = zFemaleRBt.Text;
  40.             //--------------------
  41.  
  42.  
  43.  
  44.  
  45.             string matter = "<u><strong> Personal Detail :: </strong></u><br/> " +
  46.                             "<br/> User Name______________ : " + zTbFName.Text + " " + zTbLName.Text +
  47.                             "<br/> Mobile Number___________ : " + zTbMobNo.Text +
  48.                             "<br/> Email___________________ : " + zEmailTb.Text +
  49.                             "<br/> DOB (dd/mm/yy)__________: " + zAgeDayDDL.Text + "/" + zAgeMonthDDL.Text + "/" + zAgeYearDDL.Text +
  50.  
  51.                             "<br/> Gender__________________ : " + ml +
  52.                 //  "<br/> Gender__________________ : "+ zMaleRBt.Text+  "/" + zFemaleRBt.Text +
  53.                             "<br/> Contact Address__________ : " + zAddressTb.Text +
  54.                             "<br/> Native City Name__________ : " + zCityNameTb.Text +
  55.  
  56.                             "<br/><hr><br/><u><strong>Professional Detail ::</strong></u><br/>" +
  57.                             "<br/> Total Experience(yy/mm)__ : " + zTotalEYDDL.Text + "/" + zTotalEMDDL.Text +
  58.                             "<br/> Job Category____________ : " + zJobCatListDDL.Text +
  59.                             "<br/> Key Skill_______________ : " + zKeySkillTb.Text +
  60.                             "<br/> Current Employer________ : " + zCurrentCNameTb.Text +
  61.                             "<br/> Current Salary (p.a.)______ : " + zCSalaryTb.Text +
  62.                             "<br/> Expected Salary (p.a.)____ : " + zESalaryTb.Text +
  63.  
  64.                             "<br/><hr><br/><u><strong>Educationl Qualification ::</strong></u><br/>" +
  65.                             "<br/> Highest Qualification___ : " + zHQualificationDDL.Text +
  66.                             "<br/> Specialization_________ : " + zSpecializationDDL.Text +
  67.                             "<br/> University/College______ : " + zCollegeDDL.Text +
  68.                             "<br/> Other College_________ : " + zCollegeNotATb.Text +
  69.                             "<br/> User Resume_________ : ";
  70.  
  71.             mail.Body = matter;
  72.             mail.IsBodyHtml = true;
  73.             // ----------------
  74.  
  75.             string strFileName = Path.GetFileName(zUpload.PostedFile.FileName);
  76.             zUpload.PostedFile.SaveAs(Server.MapPath("~\\") + strFileName);
  77.             System.Net.Mail.Attachment data1 = new System.Net.Mail.Attachment(Server.MapPath(strFileName));
  78.             mail.Attachments.Add(data1);
  79.  
  80.  
  81.  
  82.             mail.Priority = MailPriority.High;
  83.  
  84.  
  85.     SmtpClient smtp = new SmtpClient();
  86.             //smtp.Port = 587;
  87.             smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
  88.            smtp.Credentials = new System.Net.NetworkCredential("frommailaddress.com", "password");
  89.             //Or your Smtp Email ID and Password
  90.             smtp.EnableSsl = true;
  91.             smtp.Send(mail);
  92.             zSubmitResp.Visible = true;
  93.             zSubmitResp.Text = "Record Successfully Submitted";
  94.             //zSubmitResp.Text = strFileName;
  95.             //--------
  96.  
  97.             zTbFName.Text = "";
  98.             zTbLName.Text = "";
  99.             zTbMobNo.Text = "";
  100.             zESalaryTb.Text = "";
  101.             zEmailTb.Text = "";
  102.             zCurrentCNameTb.Text = "";
  103.             zCSalaryTb.Text = "";
  104.             zCityNameTb.Text = "";
  105.             zAddressTb.Text = "";
  106.             zCollegeNotATb.Text = "";
  107.  
  108. }
  109.  
  110.         catch (Exception ec)
  111.         {
  112.             zSubmitResp.Visible = true;
  113.             zSubmitResp.Text = ec.ToString();
  114.             }
  115.  
  116.  
  117.     }
  118. }
Aug 23 '10 #1
1 1227
Frinavale
9,735 Expert Mod 8TB
You need permissions to the folder (on the server) where your file is being uploaded to.

When debugging your application using Visual Studio, your application is run under your user account. Your user account likely has permissions to write the file into the folder.

However, when your application is run on a webserver the user account that it is run under has very limited permissions and it is likely that this account is not permitted to write the file to the folder.

-Frinny
Aug 25 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Muppy | last post by:
I've created a page with a form to upload files: <h1>Upload di un file</h1> <form enctype="multipart/form-data" method="post" action="do_upload1.php"> <p><strong>File da trasferire:</strong><br>...
3
by: MeAndI | last post by:
Hi to all, How can I put a file via FTP using the ASP pages? Please help
0
by: Pedro Bautista | last post by:
Status: Unsolved and puzzling Steps to reproduce the error: 1.- Delete IUSER from server 2.- Reboot server (OS rebuilds IUSR) 3.- Assign IUSR read and execute permission on web folder and...
3
by: tshad | last post by:
Is there a way to use a custom button with the: <Input ID="MyFile" Type="File" RunAt="Server">? This gives you a generic button, but I would like to use my own button that has the same style...
0
by: zamuel | last post by:
I have an upload problem. When I push the button the file should be saved to files folder. The if sentence doesn't work altough I browse file to "MyFile1" before pushing th button. Any ideas? ...
1
by: fiyah | last post by:
Hi all.. i am very new in this forum..but i hope somebody can help me to solve this problem now i am using C#.net in windows flatform and i having a problem to add a file upload functionality...
1
by: mzmishra | last post by:
Hi, My web.config is set to allow 5MB file size to be uploaded in my application. I want to show one alert message to the user when uploaded file size is greater than that. How can I do the...
2
by: vinodkus | last post by:
dear sir/madam I have to do something like this that a user see list of record if he would find record and want to upload that list then he could upload in a pdf file of that record. please help...
3
crystal2005
by: crystal2005 | last post by:
Hi all, Basically, i'm trying to create temporary file using TemporaryFile() module. TemporaryFile( ]]]]) It's done perfectly to create an intended file. But, i encountered a problem to...
3
by: haytham2008 | last post by:
hi every body can i upload file using ajax ?? if yes how pleaze with code thank u in advance
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.