-1

I am coping the images through picture dialogue box but I get exception

"Incorrect Username and Password"

Below are my codes

        Picture_OpenFileDialog.ShowDialog()
        filename = Picture_OpenFileDialog.SafeFileName
        fileurl = Picture_OpenFileDialog.FileName
        Picture_PictureBox.SizeMode = ImageLayout.Zoom
        If filename = "" Then

            MsgBox("File Not Selected", MsgBoxStyle.OkOnly, "Image Loading Failed")

        Else
            Picture_PictureBox.Load(fileurl)

            desiredplace = "\\SAP\Images\" & filename  
            FileCopy(fileurl, desiredplace)

How can I provide Username/Password in this?

Aditya
  • 2,876
  • 4
  • 34
  • 30

1 Answers1

0

I assume you have a button that opens the Picture_OpenFileDialog on Click Event. So your code must look like this:

Imports System.ComponentModel
Imports System.IO
Imports System.Globalization

Public Class Form1
Dim extn As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Picture_OpenFileDialog.ShowDialog()

End Sub

Private Sub Picture_OpenFileDialog_FileOk(sender As Object, e As CancelEventArgs) Handles Picture_OpenFileDialog.FileOk

    If (CheckFileType(Picture_OpenFileDialog.FileName)) Then
        'Make sure the directory you want to save to exist, otherwise you will get DirectoryNotFoundException
        'If this is the same directory that your code is running, I suggest you do it this way:
        Dim desiredplace As String = Directory.GetCurrentDirectory & "\SAP\Images\" & ExtractFilename(Picture_OpenFileDialog.FileName)
        'If not, use your desiredplace
        'Dim desiredplace As String = "\\SAP\Images\" & ExtractFilename(Picture_OpenFileDialog.FileName)

        FileSystem.FileCopy(Picture_OpenFileDialog.FileName, desiredplace)

    Else
        MessageBox.Show("Please select a picture with a file format extension of either Bmp, Jpg, Jpeg, Gif or Png.", "invalid image", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Exit Sub
    End If
End Sub
Function CheckFileType(ByVal fileName As String) As Boolean

    Dim ext As String = Path.GetExtension(fileName)

    Select Case ext.ToLower()

        Case ".gif"
            extn = ".gif"
            Return True

        Case ".png"
            extn = ".png"
            Return True

        Case ".jpg"
            extn = ".jpg"
            Return True

        Case ".jpeg"
            extn = ".jpeg"
            Return True

        Case ".bmp"
            extn = ".bmp"
            Return True

        Case Else

            Return False

    End Select

End Function
Public Function ExtractFilename(filepath As String) As String
    ' If path ends with a "\", it's a path only so return String.Empty.
    If filepath.Trim().EndsWith("\") Then Return String.Empty

    ' Determine where last backslash is.
    Dim position As Integer = filepath.LastIndexOf("\"c)
    ' If there is no backslash, assume that this is a filename.
    If position = -1 Then
        ' Determine whether file exists in the current directory.
        If File.Exists(Environment.CurrentDirectory + Path.DirectorySeparatorChar + filepath) Then
            Return filepath
        Else
            Return String.Empty
        End If
    Else
        ' Determine whether file exists using filepath.
        If File.Exists(filepath) Then
            ' Return filename without file path.
            Return filepath.Substring(position + 1)
        Else
            Return String.Empty
        End If
    End If
End Function
End Class
kilojoules88
  • 51
  • 1
  • 11
  • This is not fair way to take answer can be a person disheart obviously this cod run under a button click . Thanks for the helping me so nice man but i have a problem in this i want to copy from client and past on the server machine in this way Dim desiredplace As String = Directory.GetCurrentDirectory & "\SAP\Images\" & ExtractFilename(Picture_OpenFileDialog.FileName) desiredplace store client directory and given path plus filename but i think desiredplace only have server directory and file name not a client directory . – Mohammad Noman Mar 03 '16 at 05:51
  • you can suggest me how i can set the server path that performed an action for example i have a desiredplace server IP 192.168.1.132 have E directory and folder images that a place where i want to paste but when i paste this address occur a exception The user name or password is incorrect. – Mohammad Noman Mar 03 '16 at 06:07
  • Please tell me any way – Mohammad Noman Mar 03 '16 at 06:08
  • In that case I suggest you follow this link: http://stackoverflow.com/questions/766033/copy-file-to-remote-computer-using-remote-admin-credentials/766086#766086 – kilojoules88 Mar 03 '16 at 08:49
  • Thanks for helping me – Mohammad Noman Mar 07 '16 at 11:23