本文介绍了错误 - 文件正在使用中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!!



我正在拍摄用户的照片,然后保存它们。每次用户点击他的照片时,它都会保存在Images文件夹中。现在,用户可以拍摄他喜欢的尽可能多的照片,但是如果为该用户拍摄,则特定用户的每张照片都会替换前一张照片,因此我总是只有1张照片供1位用户使用。现在有时它说文件正在使用中。我该怎么办 ??



这里是代码。



hello!!

i am taking photographs of the user and then saving them . every time user clicks his photograph is taken and then it gets saved inside Images folder. now the user can take as many photographs as he likes but each photograph for a particular user replaces the previous one if taken for that user so i always have only 1 photograph for 1 user. now sometimes it says file is in use. what should i do ??

here is the code.

void CreatePhoto()
    {
        try
        {
            filename = getPassNo() + "-"+ DateTime.Now.Year.ToString();

            if( File.Exists(Server.MapPath("Images/" + filename)))
            {
                
                File.Delete(Server.MapPath("Images/" + filename));
  
            }
            string strPhoto = Request.Form["imageData"]; //Get the image from flash file
            byte[] photo = Convert.FromBase64String(strPhoto);
            FileStream fs = new FileStream(Server.MapPath("Images/" + filename), FileMode.OpenOrCreate, FileAccess.Write);
            
            BinaryWriter br = new BinaryWriter(fs);
            
            br.Write(photo);
           
            br.Flush();
          
            br.Close();
           
            fs.Close();
            string x = "Update Image Set Taken =1";
            Dal.ExnonQry(x);
         

        }
        catch (Exception Ex)
        {

        }
        finally
        {
           
            Response.Redirect("Default.aspx?FN=" + filename + "");
        }
    }

推荐答案


这篇关于错误 - 文件正在使用中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 04:28