The process cannot access the file

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

The process cannot access the file

michael
hi there,

i'm using NeatUpload-1.3.14 on iis 5.1. i have read through your forums and have found others with the same problem and the solution was to close the stream and it generally worked. well i've closed all streams and i am still getting the problem. i have restarted the server and have rebooted the machine with no luck. it had been working fine and just stopped working....

this is the error:

Exception Details: System.IO.IOException: The process cannot access the file 'C:\Inetpub\wwwroot\dataManagement\app_data\NeatUpload_Temp\54d91f76187c4f7baddb40e480c1f72e.config' because it is being used by another process.



this is the relevant code:



protected void UploadButton_Clicked(object sender, EventArgs e)
    {
        if (!this.IsValid)
        {
            bodyPre.InnerText = "Page is not valid!";
            return;
        }
        bodyPre.InnerText = "glowik mike";

        if (inputFile.HasFile)
        {
           
            DataSet myDataSet = CsvUtilities.ReadCsvTemplate(inputFile.FileContent);
           
           
            DataTable dt = myDataSet.Tables[0];
           
            try
            {
                SaveCsv(dt);

                this.Cmoid = this.entity.Cmoid;
                this.SchoolYearID = this.fullTimeEmployees.SchoolYearID;

                this.mv.ActiveViewIndex = BrowseView;
                LoadGrid();
            }
            catch (Exception ex)
            {
                this.lblSaveError.Text = ex.Message;
            }
            

        }
        inputFile.Dispose();
        inputFile.FileContent.Close();
       
        //Response.Redirect("Cmo_admin.aspx?Cmoid=" + this.Cmoid);
    }



public static DataSet ReadCsvTemplate(Stream stream)
        {
            string strLine;
            string[] strArray;
            char[] charArray = new char[] { ',' };
            DataSet ds = new DataSet();
            DataTable dt = ds.Tables.Add("TheData");

         
            StreamReader sr = new StreamReader(stream);
           
            strLine = sr.ReadLine();
            strArray = strLine.Split(charArray);

            for (int x = 0; x <= strArray.GetUpperBound(0); x++)
            {
                dt.Columns.Add(strArray[x].Trim());
            }
           

            strLine = sr.ReadLine();
          
            while (strLine != null)
            {
                strArray = strLine.Split(charArray);
                DataRow dr = dt.NewRow();
                for (int i = 0; i <= strArray.GetUpperBound(0); i++)
                {
                    dr[i] = strArray[i].Trim();
                }
                dt.Rows.Add(dr);
                strLine = sr.ReadLine();
            }
            /****/
            sr.Close();
            stream.Close();
            return ds;
        }


any help would be appreciated!

thanks,

michael
Reply | Threaded
Open this post in threaded view
|

Re: The process cannot access the file

Dean Brettle
Administrator
Does removing the call to inputFile.Dispose() fix the problem?
Reply | Threaded
Open this post in threaded view
|

Re: The process cannot access the file

Guest-989

no.

thanks for the prompt reply.

Reply | Threaded
Open this post in threaded view
|

Re: The process cannot access the file

Dean Brettle
Administrator
Did you recently upgrade to 1.3.14 from some other version?  If so, is that when the problem started occurring?

Is the temp filename that is mentioned in the error message always the same, or is it different each time?

Do the following changes (in bold) help?

protected void UploadButton_Clicked(object sender, EventArgs e)
    {
        if (!this.IsValid)
        {
            bodyPre.InnerText = "Page is not valid!";
            return;
        }
        bodyPre.InnerText = "glowik mike";

        if (inputFile.HasFile)
        {
            Stream ifs = inputFile.FileContent;
            DataSet myDataSet = CsvUtilities.ReadCsvTemplate(ifs);
           
           
            DataTable dt = myDataSet.Tables[0];
           
            try
            {
                SaveCsv(dt);

                this.Cmoid = this.entity.Cmoid;
                this.SchoolYearID = this.fullTimeEmployees.SchoolYearID;

                this.mv.ActiveViewIndex = BrowseView;
                LoadGrid();
            }
            catch (Exception ex)
            {
                this.lblSaveError.Text = ex.Message;
            }
            

        }
        inputFile.Dispose();
        inputFile.FileContent.Close();
        ifs.Close();
       
        //Response.Redirect("Cmo_admin.aspx?Cmoid=" + this.Cmoid);
    }
Reply | Threaded
Open this post in threaded view
|

Re: The process cannot access the file

Guest-989
hi dean,

i solved the problem. there was a bug in my code where i am looping thru the csv file. perhaps the code never made it to sr.Close(); or stream.Close(); and hence the error. sorry and thanks. -michael