简体   繁体   English

Telerik AsyncUpload尝试重命名文件获取IOException

[英]Telerik AsyncUpload trying to rename file get IOException

i want to rename my file. 我想重命名我的文件。 But i got a IOException. 但是我有一个IOException。 It says "The Process Cannot Access the File Because It Is Being Used by Another Process". 它说:“该进程无法访问文件,因为它正在被另一个进程使用”。

This is my Code: 这是我的代码:

asp.net: asp.net:

<telerik:RadAsyncUpload ID="rauKachelUpload" runat="server" ChunkSize="0" Localization-Cancel="Löschen" Localization-Remove="Entfernen" Localization-Select="Auswählen"
  Culture="de-DE" Skin="MetroTouch" MaxFileInputsCount="1" OnFileUploaded="rauKachelUpload_FileUploaded">
</telerik:RadAsyncUpload>

vb.net: vb.net:

Protected Sub rauKachelUpload_FileUploaded(sender As Object, e As FileUploadedEventArgs)

    Try
        Using fileStream As Stream = e.File.InputStream
            Using img As System.Drawing.Image = System.Drawing.Image.FromStream(fileStream)
                Dim h As Integer = img.Height
                Dim w As Integer = img.Width
                img.Dispose()
                Dim fileName As String = e.File.GetName()
                If w = MaxWidth And h = MaxHeight Then
                    rauKachelUpload.TargetFolder = "img/kachel_grafik"

                    Dim TimeStamp As String = DateDiff("s", "01/1/1970 12:00:00 AM", DateTime.Now)
                    fileName = "KI_" & TimeStamp & WelcheSparteUndGröße

                    KachelPfad = "~/img/kachel_grafik/" & fileName
                Else
                    KachelFalsch = True
                End If
                If KachelFalsch = False Then

                    e.File.SaveAs(fileName)

                    Page.ClientScript.RegisterClientScriptBlock([GetType](), "CloseScript", "redirectParentPage('VermittlerBearbeiten.aspx?ID=" & VermittlerID & "&KBFN=" & KachelPfad & "&NA=true" & "&fwg=" & WelcheSparteUndGröße & "&Ang1=" & hfAng1CHK.Value & "&Ang2=" & hfAng2CHK.Value & "&Ang3=" & hfAng3CHK.Value & "&Ang4=" & hfAng4CHK.Value & "&AngSrc1=" & hfKachelIMGSrcBaufi.Value & "&AngSrc2=" & hfKachelIMGSrcImmo.Value & "&AngSrc3=" & hfKachelIMGSrcPhoto.Value & "&AngSrc4=" & hfKachelIMGSrcAsse.Value & "');", True)
                Else
                    rnfIconNichtErzeugt.Visible = True
                End If
            End Using
        End Using
    Catch ex As Exception
        rnfIconNichtErzeugt.Visible = True
    End Try

End Sub

Without trying to rename my file, it works fine. 无需尝试重​​命名我的文件,它就可以正常工作。

Does anyone has an Idea what i did wrong? 有谁知道我做错了什么?

Thanks for reading. 谢谢阅读。 Daniel 丹尼尔

You need to make sure that the fileStream is properly closed before attempting to rename the file since the particular file will be held by the fileStream object. 尝试重命名文件之前,您需要确保fileStream已正确关闭,因为特定的文件将由fileStream对象保存。 You can try fileStream.Close() after the img.Dispose() statement. 您可以在img.Dispose()语句之后尝试fileStream.Close()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM