access to the path "C:\" is denied

I am attempting to save plain text from a plain box named 'quote'. However whenever I click the save button in the savedialogbox I am returned with the message: "access to the path "C:\" is denied"

Any suggestions

This is in debug mode & using an admin account, changing the path seems to make no difference

Private Sub saveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveToolStripButton.Click

Dim MySaveDialog As New SaveFileDialog

MySaveDialog.Filter = "Plain Text (.txt)|*.txt"

MySaveDialog.Title = "Save File"

Dim result As DialogResult = MySaveDialog.ShowDialog()

If Not result = Windows.Forms.DialogResult.Cancel Then

Try

If My.Computer.FileSystem.FileExists(MySaveDialog.FileName) = True Then

My.Computer.FileSystem.DeleteFile(MySaveDialog.FileName)

End If

WriteText(MySaveDialog.Filter)

Catch ex As Exception

MessageBox.Show("problem: " & ex.Message)

End Try

End If

End Sub

Public Sub WriteText(ByVal Path As String)

Using MyStreamWriter As IO.StreamWriter = File.CreateText("C:\")

MyStreamWriter.Write(quote.Text)

End Using

End Sub




Answer this question

access to the path "C:\" is denied

  • nmfl

    Thankyou very much for your help, and your addition of the code was invaluable (as I'm sure you can tell I am new at this).

    Sincerely,

    Nato4



  • aamer4u

    Its a simple problem.

    Your file.createtext line is attempting to create a file called "c:\"

    Try something similar to this

    Just create a form with a textbox (multiline), a button and a savefiledialog

    Imports System.IO

    Public Class Form1

    Private FiletoSave As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub WriteText(ByVal Path As String)

    Using mystreamwriter As IO.StreamWriter = File.CreateText(FiletoSave)

    mystreamwriter.Write(TextBox1.Text)

    End Using

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    If MySaveDialog.ShowDialog = Windows.Forms.DialogResult.OK Then

    FiletoSave = MySaveDialog.FileName

    WriteText(FiletoSave)

    End If

    End Sub


  • Spuddo

    No problem at all :) Im pretty new myself still :)
  • access to the path "C:\" is denied