C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

kindly resolve the below error


Posted Date: 26 Jul 2008      Posted By: Sridharan      Member Level: Silver     Points: 1   Responses: 1



Hi;



i am sendint the email with attachment means its shown follwing error using asp.net and error meassage like


System.UnauthorizedAccessException: Access to the path "c:\inetpub\wwwroot\mailattach\1.xls" is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at mailattach.WebForm1.btnSend_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\mailattach\WebForm1.aspx.vb:line 85


source code is



Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Try
' Create a New blank MailMessage */
Dim mailMessage As MailMessage = New MailMessage

mailMessage.From = txtSender.Text
mailMessage.To = txtReceiver.Text
mailMessage.Cc = txtCc.Text
mailMessage.Bcc = txtBcc.Text
mailMessage.Subject = txtSubject.Text
mailMessage.Body = txtBody.Text
' Set the properties of the MailMessage to the
' values on the form */
If rblMailFormat.SelectedItem.Text = "Text" Then
mailMessage.BodyFormat = MailFormat.Text
Else
mailMessage.BodyFormat = MailFormat.Html
End If
' We use the following variables to keep track of
' attachments and after we can delete them */
Dim attach1 As String = Nothing
Dim attach2 As String = Nothing
Dim attach3 As String = Nothing
' strFileName has a attachment file name for
' attachment process. */
Dim strFileName As String = Nothing
' Bigining of Attachment1 process &
' Check the first open file dialog for a attachment */
If Not inpAttachment1.PostedFile Is Nothing Then
' Get a reference to PostedFile Object */
Dim attFile As HttpPostedFile = inpAttachment1.PostedFile ' Get size of the file */
Dim attachFileLength As Integer = attFile.ContentLength ' Make sure the size of the file is > 0 */
If attachFileLength > 0 Then
' Get the file name */
strFileName = Path.GetFileName(inpAttachment1.PostedFile.FileName) ' Save the file on the server */
inpAttachment1.PostedFile.SaveAs(Server.MapPath(strFileName)) ' Create the email attachment with the uploaded file */
Dim attach As MailAttachment = New MailAttachment(Server.MapPath(strFileName)) ' Attach the Newly created email attachment */
mailMessage.Attachments.Add(attach) ' Store the attach filename so we can delete it later */
attach1 = strFileName
End If
End If
If Not inpAttachment2.PostedFile Is Nothing Then
Dim attFile As HttpPostedFile = inpAttachment2.PostedFile
Dim attachFileLength As Integer = attFile.ContentLength
If attachFileLength > 0 Then
strFileName = Path.GetFileName(inpAttachment2.PostedFile.FileName)
inpAttachment2.PostedFile.SaveAs(Server.MapPath(strFileName))
Dim attach As MailAttachment = New MailAttachment(Server.MapPath(strFileName))
mailMessage.Attachments.Add(attach)
attach2 = strFileName
End If
End If
If Not inpAttachment3.PostedFile Is Nothing Then
Dim attFile As HttpPostedFile = inpAttachment3.PostedFile
Dim attachFileLength As Integer = attFile.ContentLength
If attachFileLength > 0 Then
strFileName = Path.GetFileName(inpAttachment3.PostedFile.FileName)
inpAttachment3.PostedFile.SaveAs(Server.MapPath(strFileName))
Dim attach As MailAttachment = New MailAttachment(Server.MapPath(strFileName))
mailMessage.Attachments.Add(attach)
attach3 = strFileName
End If
End If
' Set the SMTP server and send the email with attachment */

' SmtpMail.SmtpServer = "127.0.0.1";
SmtpMail.SmtpServer.Insert(0, "127.0.0.1")

SmtpMail.Send(mailMessage)
' Delete the attachements if any */
If Not attach1 Is Nothing Then
File.Delete(Server.MapPath(attach1))
End If
If Not attach2 Is Nothing Then
File.Delete(Server.MapPath(attach2))
End If
If Not attach3 Is Nothing Then
File.Delete(Server.MapPath(attach3))
End If
' clear the controls */
txtSender.Text = ""
txtReceiver.Text = ""
txtCc.Text = ""
txtBcc.Text = ""
txtSubject.Text = ""
txtBody.Text = ""
' Dispaly a confirmation message to the user. */
lblMessage.Visible = True
lblMessage.ForeColor = Color.Black
lblMessage.Text = "Message sent."
Catch ex As Exception
' Print a message informing the
' user about the exception that was risen */
lblMessage.Visible = True
lblMessage.ForeColor = Color.Red
lblMessage.Text = ex.ToString()
End Try

End Sub




End Class








Responses

Author: VMRK    26 Jul 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 1

did u check the presence of excel sheet n the mentioned path


Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : diff b/w server.Execute and resposce.redirect
Previous : what is server.Flush method and diff b/w
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use