MasoudAdmin
شنبه 10 مهر 1400, 23:26 عصر
با سلام
من یک کد نوشتم که فایل Word رو از دیتابیس بخونه و بعد پارامترها رو Replace کنه و در فولدر MyDocument ویندوز ذخیره کنه. ولی موقع ذخیره شدن در فولدری که اعلام کردم خطای دسترسی میده. با اینکه دسترسی Full Control هم به فولدر دادم بازم خطا میده. حتی فولدر دستی تو درایو دیگه هم تعریف کردم و دسترسی Full Control هم دادم ولی باز هم همون خطا رو داره.
mydocumentsPath= Environment.GetFolderPath(Environment.SpecialFolde r.MyDocuments) + "\\Guarantee";
if (!System.IO.Directory.Exists(mydocumentsPath))
{
System.IO.Directory.CreateDirectory(mydocumentsPat h);
Random myrandom = new Random();
int MyValue = myrandom.Next();
string sFileName = mydocumentsPath + "\\tmp" + MyValue.ToString().Trim() + Extention;
byte[] filebyte;
CmdMain.CommandText = "Select LetterBody From VW_LetterSubject Where LetterCode=" + LetterCode;
filebyte = (byte[])CmdMain.ExecuteScalar();
string sTempFileName = Application.StartupPath + sFileName;
FileStream FS = new FileStream(sFileName, FileMode.OpenOrCreate, FileAccess.Write);
FS.Write(filebyte, 0, filebyte.Length);
FS.Flush();
FS.Close();
Document document = new Document();
document.LoadFromFile(sFileName);
Dictionary<string, string> dictReplace = GetReplaceDictionary();
//Replace text
foreach (KeyValuePair<string, string> kvp in dictReplace)
{
document.Replace(kvp.Key, kvp.Value, true, true);
}
//Save doc file.
document.SaveToFile(mydocumentsPath, FileFormat.Docx);
document.Close();
ConData.Close();
}
else
{
foreach (string strFiles in System.IO.Directory.GetFiles(mydocumentsPath))
{
System.IO.File.Delete(strFiles);
}
Random myrandom = new Random();
int MyValue = myrandom.Next();
string sFileName = mydocumentsPath + "\\tmp" + MyValue.ToString().Trim() + Extention;
byte[] filebyte;
CmdMain.CommandText = "Select LetterBody From VW_LetterSubject Where LetterCode=" + LetterCode;
filebyte = (byte[])CmdMain.ExecuteScalar();
string sTempFileName = Application.StartupPath + sFileName;
FileStream FS = new FileStream(sFileName, FileMode.OpenOrCreate, FileAccess.Write);
FS.Write(filebyte, 0, filebyte.Length);
FS.Flush();
FS.Close();
Document document = new Document();
document.LoadFromFile(sFileName);
Dictionary<string, string> dictReplace = GetReplaceDictionary();
//Replace text
foreach (KeyValuePair<string, string> kvp in dictReplace)
{
document.Replace(kvp.Key, kvp.Value, true, true);
}
//Save doc file.
document.SaveToFile(mydocumentsPath, FileFormat.Docx);
document.Close();
ConData.Close();
}
اینم کدهای من هست. ولی این خطا رو میده:
153502
ممنون میشم راهنمایی کنید.
من یک کد نوشتم که فایل Word رو از دیتابیس بخونه و بعد پارامترها رو Replace کنه و در فولدر MyDocument ویندوز ذخیره کنه. ولی موقع ذخیره شدن در فولدری که اعلام کردم خطای دسترسی میده. با اینکه دسترسی Full Control هم به فولدر دادم بازم خطا میده. حتی فولدر دستی تو درایو دیگه هم تعریف کردم و دسترسی Full Control هم دادم ولی باز هم همون خطا رو داره.
mydocumentsPath= Environment.GetFolderPath(Environment.SpecialFolde r.MyDocuments) + "\\Guarantee";
if (!System.IO.Directory.Exists(mydocumentsPath))
{
System.IO.Directory.CreateDirectory(mydocumentsPat h);
Random myrandom = new Random();
int MyValue = myrandom.Next();
string sFileName = mydocumentsPath + "\\tmp" + MyValue.ToString().Trim() + Extention;
byte[] filebyte;
CmdMain.CommandText = "Select LetterBody From VW_LetterSubject Where LetterCode=" + LetterCode;
filebyte = (byte[])CmdMain.ExecuteScalar();
string sTempFileName = Application.StartupPath + sFileName;
FileStream FS = new FileStream(sFileName, FileMode.OpenOrCreate, FileAccess.Write);
FS.Write(filebyte, 0, filebyte.Length);
FS.Flush();
FS.Close();
Document document = new Document();
document.LoadFromFile(sFileName);
Dictionary<string, string> dictReplace = GetReplaceDictionary();
//Replace text
foreach (KeyValuePair<string, string> kvp in dictReplace)
{
document.Replace(kvp.Key, kvp.Value, true, true);
}
//Save doc file.
document.SaveToFile(mydocumentsPath, FileFormat.Docx);
document.Close();
ConData.Close();
}
else
{
foreach (string strFiles in System.IO.Directory.GetFiles(mydocumentsPath))
{
System.IO.File.Delete(strFiles);
}
Random myrandom = new Random();
int MyValue = myrandom.Next();
string sFileName = mydocumentsPath + "\\tmp" + MyValue.ToString().Trim() + Extention;
byte[] filebyte;
CmdMain.CommandText = "Select LetterBody From VW_LetterSubject Where LetterCode=" + LetterCode;
filebyte = (byte[])CmdMain.ExecuteScalar();
string sTempFileName = Application.StartupPath + sFileName;
FileStream FS = new FileStream(sFileName, FileMode.OpenOrCreate, FileAccess.Write);
FS.Write(filebyte, 0, filebyte.Length);
FS.Flush();
FS.Close();
Document document = new Document();
document.LoadFromFile(sFileName);
Dictionary<string, string> dictReplace = GetReplaceDictionary();
//Replace text
foreach (KeyValuePair<string, string> kvp in dictReplace)
{
document.Replace(kvp.Key, kvp.Value, true, true);
}
//Save doc file.
document.SaveToFile(mydocumentsPath, FileFormat.Docx);
document.Close();
ConData.Close();
}
اینم کدهای من هست. ولی این خطا رو میده:
153502
ممنون میشم راهنمایی کنید.