C# 是否有一种直接从sql加载文件的方法,并且我需要一种用sql中的其他映像替换映像的方法
我在SQL server数据库中有一个模板word文件 我需要在上面更改sum文本。 我尝试先将文件下载到临时文件,然后将其加载到代码中。 是否有一种方法可以使用此方法将文件直接加载到我的代码I(先将文件保存到驱动器) 之后,我需要改变图像与其他图像在数据库中C# 是否有一种直接从sql加载文件的方法,并且我需要一种用sql中的其他映像替换映像的方法,c#,c#-4.0,jsjac,C#,C# 4.0,Jsjac,我在SQL server数据库中有一个模板word文件 我需要在上面更改sum文本。 我尝试先将文件下载到临时文件,然后将其加载到代码中。 是否有一种方法可以使用此方法将文件直接加载到我的代码I(先将文件保存到驱动器) 之后,我需要改变图像与其他图像在数据库中 public Boolean save_agaza_file(string pattth) { Boolean result = false; Document wordDoc = new Docu
public Boolean save_agaza_file(string pattth)
{
Boolean result = false;
Document wordDoc = new Document();
Application wordApp = new Application();
try
{
//OBJECT OF MISSING "NULL VALUE"
Object oMissing = System.Reflection.Missing.Value;
Object oTemplatePath = pattth;
//wordDoc = new Document();
wordDoc = wordApp.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
DateTime day_start = DateTime.Now.AddDays(1);
DateTime day_end = DateTime.Now.AddDays(2);
foreach (Range rr in wordDoc.StoryRanges)
{
}
foreach (Field myMergeField in wordDoc.Fields)
{
Range rngFieldCode = myMergeField.Code;
String fieldText = rngFieldCode.Text;
// ONLY GETTING THE MAILMERGE FIELDS
if (fieldText.StartsWith(" MERGEFIELD"))
{
// THE TEXT COMES IN THE FORMAT OF
// MERGEFIELD MyFieldName \\* MERGEFORMAT
// THIS HAS TO BE EDITED TO GET ONLY THE FIELDNAME "MyFieldName"
Int32 endMerge = fieldText.IndexOf("\\");
Int32 fieldNameLength = fieldText.Length - endMerge;
String fieldName = fieldText.Substring(11, endMerge - 11);
// GIVES THE FIELDNAMES AS THE USER HAD ENTERED IN .dot FILE
fieldName = fieldName.Trim();
// **** FIELD REPLACEMENT IMPLEMENTATION GOES HERE ****//
// THE PROGRAMMER CAN HAVE HIS OWN IMPLEMENTATIONS HERE
if (fieldName == "EmpName")
{
myMergeField.Select();
// wordApp.Selection.TypeText("محمد السيد زكى");
wordApp.Selection.TypeText(this.Reqested_emp.Name);
}
}
}
}
catch (Exception e)
{
MessageBox.show(e.Message);
}
}
下载方法
string sql = @" select * from Agaza_template where template_id=" + agaza_id + ";";
if (Form1.conn.State != ConnectionState.Open)
{
Form1.conn.Open();
SqlCommand command = new SqlCommand(sql, Form1.conn);
SqlDataReader reader = command.ExecuteReader();
// reader.Read();
//if (reader.HasRows)
if (reader.Read())
{
byte[] b = (byte[])reader[2];
// string s = Path.GetFileName(reader[1].ToString());
string s = reader[1].ToString();
string result = Path.GetTempPath();
file_temp_name = result + s;
FileStream fs = new FileStream(result + s, FileMode.Create);
fs.Write(b, 0, b.Length);
fs.Close();
}
}
Form1.conn.Close();
}
看起来您正在使用Word Interop API(
Microsoft.Office.Interop.Word
)。是这样吗?您必须使用此API访问Word文档吗?如果是这样,那么就没有办法从流
打开文档(通过Word interop)。可能存在一些互操作解决方案,但我的建议是继续沿着您已经走的道路前进。我会将文件保存到Temp文件夹中,可以使用环境变量访问该文件夹(请参阅及其答案)。如果我误解了你的问题,请告诉我。正如你所说,但我在程序的写入和读取速度比硬盘快的方法上有问题,因此程序被停止,所以我使用Thread.Sleep(5000);这使得节目推迟了对不起,我不知道你的意思。我在代码中没有看到对Thread.Sleep(5000)的调用。读写操作是否同时进行,并且一个操作的速度比另一个快?