2016-03-02 24 views
-1

我應對通過圖片對話框但映像的服務器上覆制在vb.net使用從客戶

下面的圖片 我得到異常

「不正確的用戶名和密碼」桌面應用程序是我的代碼

 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) 

如何在此提供用戶名/密碼?

+0

或者告訴我其他方法 –

回答

0

我假設你有一個按鈕,在Click事件上打開Picture_OpenFileDialog。所以,你的代碼必須是這樣的:

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 
+0

這不是拿答案可以disheart顯然這鱈點擊一個按鈕下運行的人公平的方式。 感謝您幫助我這麼好的人,但我有一個問題,在這我想複製從客戶端和服務器機器上 以這種方式Dim desiredplace As String = Directory.GetCurrentDirectory&「\ SAP \ Images \」&ExtractFilename (Picture_OpenFileDialog.FileName) desiredplace存儲客戶端目錄和給定路徑加上文件名 但我認爲desiredplace只有服務器目錄和文件名稱不是客戶端目錄。 –

+0

你可以建議我如何設置執行操作的服務器路徑例如我有一個desiredplace服務器IP 192.168.1.132有E目錄和文件夾圖像,我想粘貼的地方,但是當我粘貼此地址發生異常用戶名或密碼不正確。 –

+0

請告訴我任何方式 –

相關問題