Процесс не может получить доступ к файлу «имя_файла», поскольку он используется другим процессом
[WebMethod(Description = "Work Order Proposal Print", EnableSession = true)]
public string FnConsolidateApprovePrint(int PRID, int ComId)
{
string BFtType, fileName;
string RtnStr = "";
SqlConnection SqlCon = new SqlConnection();
string UserFn;
ReportDocument rptDoc = new ReportDocument();
SqlCon = new SqlConnection(ConfigurationManager.AppSettings["BB_PHARM_CONSTR"]);
BFtType = "";
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adapter;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
try
{
SqlCon.Open();
cmd.CommandText = "workorder_proposal_report";
cmd.Parameters.Add("@PRID", SqlDbType.Int).Value = PRID;
cmd.Parameters.Add("@ComId", SqlDbType.Int).Value = ComId;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = SqlCon;
ds = new DataSet();
adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds, "DataTable1");
dt = ds.Tables[0];
UserFn = "WorkOrderProposal" + Convert.ToString(PRID);
if (dt.Rows.Count > 0)
{
if (BFtType.Length > 0)
{
if (BFtType == "PharGen")
rptDoc.Load(HttpContext.Current.Server.MapPath("crWOPropose.rpt"));
else
{
fileName = "Formats/" + BFtType + "crWOPropose.rpt";
//modified to check below line
//File.Delete(fileName);
if (File.Exists(HttpContext.Current.Server.MapPath(fileName)))
rptDoc.Load(HttpContext.Current.Server.MapPath(fileName));
else
rptDoc.Load(HttpContext.Current.Server.MapPath("crWOPropose.rpt"));
}
}
else
rptDoc.Load(HttpContext.Current.Server.MapPath("crWOPropose.rpt"));
rptDoc.SetDataSource(dt);
// Remove PrnType-related code
rptDoc.ExportToDisk(ExportFormatType.PortableDocFormat, HttpContext.Current.Server.MapPath("../Print/" + Convert.ToString(UserFn) + ".pdf"));
RtnStr = @"\\Print\" + UserFn + ".pdf";
ClearApplicationCache();
}
}
catch (Exception ex)
{
ClearApplicationCache();
throw new Exception(ex.Message);
}
finally
{
ClearApplicationCache();
cmd.Dispose();
if (SqlCon.State != ConnectionState.Closed)
SqlCon.Close();
}
return RtnStr;
}
Подробнее здесь: https://stackoverflow.com/questions/781 ... -by-anothe
Процесс не может получить доступ к файлу «имя_файла», поскольку он используется другим процессом. ⇐ Jquery
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Процесс не может получить доступ к файлу, поскольку он используется другим процессом.
Anonymous » » в форуме C# - 0 Ответы
- 15 Просмотры
-
Последнее сообщение Anonymous
-