VB Net error - Access Denied while saving PNG to Documents folder.

Jeff Rowe 96 Reputation points
2021-03-26T16:50:10.26+00:00

I am trying to save/copy a png file to the Documents folder from my Vb Net application. I can save any other type of file but an image. I can save the image to Pictures but I need to include it with other files as part of a report so I need them all in the same location. Why will it not let me put an image in the Documents folder? I can put them in there manually, I can save practically any other file there. I can save the .png as .pn_ but then it won't let me rename it. WHY????

    Public logofile As String = IO.Path.Combine(GetFolderPath(SpecialFolder.MyDocuments), "YT-Chaps\bin\logo.png")

This works

        If IO.File.Exists(logofile) = False Then
            Dim logotmp As String = logofile
            logotmp = logotmp.Substring(0, logotmp.Length - 1) & "_"
            Try
                IO.File.Copy("logo.png", logotmp, True)
            Catch ex As Exception
                MsgBox(ex.Message.ToString)
            End Try
        End If

This doesn't - "Copy Error

        If IO.File.Exists(logofile) = False Then
            Try
                IO.File.Copy("logo.png", logofile, True)
            Catch ex As Exception
                MsgBox(ex.Message.ToString)
            End Try
        End If

copy.png

I have also tried to load it to a BMP and save it using bitmap.save, I get a Generic GDI+ error when I do that.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,581 questions
{count} votes