程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了System.IO.File.InternalDelete - 进程无法访问文件大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决System.IO.File.Internaldelete - 进程无法访问文件?

开发过程中遇到System.IO.File.Internaldelete - 进程无法访问文件的问题如何解决?下面主要结合日常开发的经验,给出你关于System.IO.File.Internaldelete - 进程无法访问文件的解决方法建议,希望对你解决System.IO.File.Internaldelete - 进程无法访问文件有所启发或帮助;

我收到错误:

System.IO.IOException: 进程无法访问文件,因为它 正在被另一个进程使用。在 System.IO.__Error.WinIOError(Int32 errorCode,String mayFullPath)
在 System.IO.file.Internaldelete(String path,Boolean checkHost)

我正在正确处理所有对象,但不确定为什么会出现该异常。这不会发生在我的本地系统上,但是当我在服务器上部署时,我会间歇性地遇到这个问题

给定

private byte[] StreamToByteArray(Stream srcfilE)
{
    srcfile.position = 0; //faster than seek when dealing with an absolute 
    position.byte[] buffer = new byte[srcfile.Length];
    srcfile.Read(buffer,buffer.Length);
    return buffer;
}

private String AppendChunkData(ChunkMetaData MetaData,Stream fStream)
{
    String app_Path = Server.MapPath(UploadTemp);
    if (!System.IO.Directory.Exists(app_Path))
        System.IO.Directory.CreateDirectory(app_Path);
    String tempPath = Path.Combine(app_Path,MetaData.UploadUID + MetaData.fileName);
    byte[] byteArray = StreamToByteArray(fStream);
    using (var fileStream = new fileStream(tempPath,fileMode.Append,fileAccess.WritE))
    {
        fileStream.Write(byteArray,byteArray.Length);
    }

    return tempPath;
}

使用

String tempPath = AppendChunkData(MetaData,file.inputStream);

//Read file data from temp storage Upload to Object storage 
byte[] content = System.IO.file.ReadAllBytes(tempPath);
  
using (Stream stream = new MemoryStream(content))
{
    f.Upload(stream,data.EntityID,fullPath,data.Domain,data.org,MetaData.EntityTypE);
}

if (System.IO.file.Exists(tempPath))
    System.IO.file.delete(tempPath);   
     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的System.IO.File.InternalDelete - 进程无法访问文件全部内容,希望文章能够帮你解决System.IO.File.InternalDelete - 进程无法访问文件所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。