Процесс не может получить доступ к файлу «имя_файла», поскольку он используется другим процессом
[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
Процесс не может получить доступ к файлу «имя_файла», поскольку он используется другим процессом. ⇐ C#
Место общения программистов C#
1710823499
Гость
Процесс не может получить доступ к файлу «имя_файла», поскольку он используется другим процессом
[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;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78184246/the-process-cannot-access-the-file-filename-because-it-is-being-used-by-anothe[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия