question

JeffRowe-9143 avatar image
0 Votes"
JeffRowe-9143 asked Castorix31 commented

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

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.


dotnet-visual-basic
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Did you try to keep the .png extension, but to change the name: logo2.png, for example.


0 Votes 0 ·

Yes, it's not trying to overwrite and even if it was, that is what the ", true" is for.

0 Votes 0 ·

Does it work in case of logo2.png, or the same Access Denied error is shown regardless the target name?

0 Votes 0 ·
Show more comments

If I do a random test, I can save a .png to Documents folder on my OS :

         Dim logofile As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "logo.png")
         Using bmp = New Bitmap(Me.Width, Me.Height)
             Me.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height))
             bmp.Save(logofile, System.Drawing.Imaging.ImageFormat.Png)
         End Using
0 Votes 0 ·

0 Answers