---
title: "ladda upp fil - klass"
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/71570-ladda-upp-fil-klass"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "P"
published: "2003-03-19T16:21:25.000Z"
updated: "2003-03-20T16:35:12.000Z"
replies: 2
views: 184
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/71570-ladda-upp-fil-klass"
---

# ladda upp fil - klass

## #1 — P, 2003-03-19T16:21Z

Försöker ladda upp en fil utanför codebehind. Koden ser ut så här:
aspx filen

```
<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>
```

Inga konstigheter här

i codebehind:

```
    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
```

och sen i Businessklassen: 

```
    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....
```

Error: Object variable or With block variable not set. Linjen med \*\*\*

Permalänk: https://www.webforum.nu/p/71570

## #2 — P, 2003-03-19T19:06Z

fungerar nu... byte ut lite File mot File för File finns tydligen i IO

Permalänk: https://www.webforum.nu/p/984045

## #3 — cyprys, 2003-03-20T16:35Z

> byte ut lite File mot File för File finns tydligen i IO

 :birp

Permalänk: https://www.webforum.nu/p/984568

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/71570-ladda-upp-fil-klass
