Försöker ladda upp en fil utanför codebehind. Koden ser ut så här: fungerar nu... byte ut lite File mot File för File finns tydligen i IOladda upp fil - klass
aspx filen
<code>
<form id="Form1" encType="multipart/form-data" runat="server">
<P>Välj en fil: <INPUT id="File1" type="file" runat="server"></P>
<P>Beskrivning:
<asp:textbox id="tbDescription" runat="server" Height="76px" Width="208px" TextMode="MultiLine"></asp:textbox></P>
<P><asp:button id="btnUpload" runat="server" Text="Ladda upp"></asp:button></P>
<P><asp:label id="lblMessage" runat="server"></asp:label></P>
<P><asp:label id="lblMessage2" runat="server"></asp:label></P>
</form>
</code>
Inga konstigheter här
i codebehind:
<code>
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Dim strPath As String = Server.MapPath(".") & "\Pictures\"
lblMessage.Text = Gallery.SaveFile(strPath, File, tbDescription.Text)
lblMessage2.Text = Gallery.CreateTumbNail(strPath, File.PostedFile.FileName)
End Sub
</code>
och sen i Businessklassen:
<code>
Public Shared Function SaveFile(ByVal strPath As String, ByVal File As Object, ByVal strDesc As String)
Dim objData As New GalleryDB()
Dim strFilePath As String = File.PostedFile.FileName ' ***
Dim strFileName As String = GetName(strFilePath) & "." & GetExtension(strFilePath)
If Not (File.PostedFile Is Nothing) Then
Try
File.PostedFile.SaveAs(strPath & strFileName)
Catch Exp As Exception
Return Exp.ToString()
' more code here....
</code>
Error: Object variable or With block variable not set. at line with ***Sv: ladda upp fil - klass