有没有一种方法可以直接从sql加载文件,而我需要一种用sql中的其他图像替换图像的方法

时间:2018-09-10 21:53:58

标签: c# c#-4.0 jsjac

我在SQL Server数据库数据库中有一个模板字文件 我需要更改它的总和文本。 我尝试先将文件下载到临时文件,然后再将其加载到代码中。  有没有一种方法可以直接使用我的文件将文件加载到我的代码中(保存文件先驱动)  之后,我需要用数据库中的其他图像来更改图像。

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();

            }

0 个答案:

没有答案