2016-12-28 6 views
0

ファイルアップロードとアップロードのリンクボタンと送信ボタンがあります。ファイルを選択してアップロードをクリックすると、ファイル名がラベルに表示されます。再びラベルに保存したファイルを選択し、[ファイル名をアップロードをクリックすると、その..ラベルすなわちvb.netに文書名と文書パスを挿入する

abc.docx 
def.docx 

で複数のファイル名表示を意味し、その..に

は今、私は、データベースにこれらのファイルを保存しようこれらのファイルがデータベーステーブルに保存されている場合は、別のレコードを意味します。

このため210
ID DocumentName DocumentPath 
1 abc.docx /downloads/abc.docx 
2 def.docx /files/def.docx 

私はこれをしようとすると、私はこの SP

 alter procedure spupload_file 
    @DocumentName varchar(100), 
    @Doctype tinyint 
    as 


    insert into DocDownloads (DocumentID,DocumentName,DocType) 

    select (select max(DocumentID) from DocDownloads)+ROW_NUMBER() over(order by @DocumentName),@DocumentName,7 

コード

 Protected Sub LinkButton1_Click(sender As Object, e As EventArgs) Handles LinkButton1.Click 
     uploadmultiple_file(fileUpEx.FileName) 
    End Sub 

    Public Sub uploadmultiple_file(filename As String) 
     If fileUpEx.HasFiles Then 
      For Each uploadedfile As HttpPostedFile In fileUpEx.PostedFiles 
       'Label4.Text = ("<b>File: </b>" + uploadedfile.FileName) 
       Label4.Text += String.Format("{0}<br />", uploadedfile.FileName) 
      Next 
     End If 
    End Sub 


Protected Sub pb_Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles pb_submit.Click 
    Dim strKeyName() As String = {"DocumentName", "DocType"} 
     Dim objKeyVal() As Object = {Label4.Text,7} 
     structDb = objDataSet.ExecSP("tbl", "spupload_file", strKeyName, objKeyVal) 
     If structDb.intCode = 0 Then 
      Label5.Text = structDb.strMessage 
      Label5.CssClass = "error" 
      Exit Sub 
     End If 


    End Sub 

を試してみてください...これは

1 abc.docx<br />def.docx<br /> 

などのようなデータベーステーブル内のレコードを示しています私はこのようにしたいです

1 abc.docx 
2 def.docx 

インデックスが配列の境界外にありました。

どのようにドキュメントパスを挿入するのですか?

助けてください。

は、私はこの

For Each file As HttpPostedFile In ListBox1.Items 
     Dim DocumentName As String = file.FileName 

     Dim strKeyName() As String = {"DocumentName", "DocType"} 
     Dim objKeyVal() As Object = {DocumentName, 7} 
structDb = objDataSet.ExecSP("tbl", "spupload_file", strKeyName, objKeyVal) 

    Next 


    If structDb.intCode = 0 Then 
     Label5.Text = structDb.strMessage 
     Label5.CssClass = "error" 
     Exit Sub 
    End If 

を試してみたが、これは誤り

タイプの例外を示して 'System.InvalidCastExceptionの' @Andyリード に応じ

[OK]を更新しましたがDecibelCRMで発生しました。 dllがユーザーコードで処理されませんでした 追加情報: 'System.Web.UI.WebControls'型のオブジェクトをキャストすることができません。 ListItem 'を入力して' System.Web.HttpPostedFile 'と入力します。

答えて

1

をお試しください各PostedFileを新しい行としてDocDownloadsに配置する必要があります。さらに多くの調査を行うと、セキュリティ上の理由により完全なパスにアクセスできません

+0

私はあなたにソリューションを試してみてください、しかし、これはエラーを示しています..私の質問で更新されたコードを確認してください。 –

+0

'objDataSet.ExecSP()'のコードはどうなっていますか? 私の答えは、 'objDataSet.DocDownloads.AddDocDownloadsRow(DocumentName、DocType)' ...これは、 'spupload_file'にしたいことをしているはずです。基本的には、DocumentNameとDocTypeを使用してobjDataSetのDocDownloadsテーブルに新しい行を挿入します。 –

0

あなたのコード:

Public Sub uploadmultiple_file(filename As String) 
     If fileUpEx.HasFiles Then 
      For Each uploadedfile As HttpPostedFile In fileUpEx.PostedFiles 
       'Label4.Text = ("<b>File: </b>" + uploadedfile.FileName) 
       Label4.Text += String.Format("{0}<br />", uploadedfile.FileName) 
      Next 
     End If 
    End Sub 

データセットの文書IDが自動インクリメント

Protected Sub UploadLinkButton_Click(sender As Object, e As EventArgs) Handles UploadLinkButton.Click 
    uploadmultiple_file(FileUpEx.FileName) 

End Sub 

Public Sub uploadmultiple_file(filename As String) 
    If fileUpEx.HasFiles Then 
     'Add each PostedFile to list Box instead of using label 
     For Each uploadedfile As HttpPostedFile In fileUpEx.PostedFiles 
      FilesListBox.Items.Add(uploadedfile.FileName) 
     Next 

    End If 

End Sub 

Protected Sub pb_Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitButton.Click 
    Dim objDataSet As New objDataSet 'Or whatever you have 
    Dim DocType as Integer = 7 

    'Gets each file from FilesListBox to insert them into objDataSet   
    For Each file As HttpPostedFile In FilesListBox.Items 
     Dim DocumentName as String = file.FileName 

     'Because the DocumentID is AutoIncrement, you don't need to enter it here 
     objDataSet.DocDownloads.AddDocDownloadsRow(DocumentName, DocType) 

    Next 

End Sub 

である場合、これは、データテーブルのためになり、代わりにLabel4からのリストボックスを使用して

Public Sub uploadmultiple_file(filename As String) 

    If fileUpEx.HasFiles Then 
    Try 
     For Each uploadedfile As HttpPostedFile In fileUpEx.PostedFiles      
      Label4.Text += uploadedfile.FileName & vbCRLF 
      'Possibly something like: "Label4.Text += uploadedfile.FullPath & vbCRLF" for the document path 
     Next 

    Catch ex as Exception 
     'Whatever exception handling code  
    End try 

    End If 

End Sub 
+0

これはパスのためのものですか?テーブルのデータはどうですか? –

関連する問題