将自动生成的文件保存到物理存档器中 [英] saving of automated generated file into physical filder

查看:58
本文介绍了将自动生成的文件保存到物理存档器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

我正在使用ActiveX对象和windows.shell归档填充一个.dot(template)文件.该文档正在生成,但问题是它仅保存在特殊文件夹中,例如桌面,开始菜单,我的文档,Cookie,例如我想将该文档保存在我的项目文件夹中.请参阅代码,我在给定绝对路径的地方更改了桌面的路径,但无法正常工作.谁能帮我.






Hi Friends,

I am filing filling one .dot(template) file using ActiveX objects and windows.shell. the document is generating but problem is it is saving in only special folders like Desktop, Start Menu, My documents,Cookies like i want to save that document in my project folder. Please See the code,,,,, I changed the path in the place of Desktop i given Absolute path but not working. Can any one help me.






public string generateWord(string redirect_url, int pg, string template, string[] bookmarks, string[] values, int[] tickCheckBox, int[] underline, int[] bold)
    {
            Utility utility = new Utility();
            string jScript = "<script type=\"text/javascript\" language=\"JScript\">";
            jScript += "try {";
            jScript += "var word = new ActiveXObject('Word.Application');";
            jScript += "if (word != null){";
            jScript += "obj=word.Documents.Open('" + utility.getBaseUrl() + "/doc/template/" + template + ".dot',true);";
            jScript += "word.Visible = true;";
            jScript += "docText = obj.Content;";
            jScript += "var Document=word.ActiveDocument;";
            jScript += "obj.Select();";
            for (int i = 0; i < bookmarks.Length; i++)
            {
                if (tickCheckBox[i].Equals(1))
                {
                    if (values[i].Equals("1"))
                    {
                        jScript += "var objRange = obj.Bookmarks('" + bookmarks[i] + "').Range;objRange.Text = String.fromCharCode(252);objRange.Font.Name='Wingdings';objRange.Font.Size=12;objRange.Font.Bold=1;";
                    }
                }
                else
                {
                    jScript += "var objRange = obj.Bookmarks('" + bookmarks[i] + "').Range;objRange.Text='" + values[i] + "';objRange.Font.Underline=" + underline[i] + ";objRange.Font.Bold=" + bold[i] + ";";
                }
            }
            string sp = utility.getSavePath();
            sp = sp.Replace("\\", "\\\\");
            sp.Replace("\\\\\\\\", "\\\\");
            
            jScript += "var objWSH= new ActiveXObject( 'WScript.shell' );";
            
            jScript += "var desktop = objWSH.SpecialFolders('StartMenu');";
            jScript += "var objFileObject = new ActiveXObject('Scripting.FileSystemObject');";
            jScript += "var pathstring = objFileObject.GetAbsolutePathName(desktop);";
            jScript += "var desktop1 = objWSH.SpecialFolders('Desktop');";
            jScript += "var objFileObject1 = new ActiveXObject('Scripting.FileSystemObject');";
            jScript += "var pathstring1 = objFileObject1.GetAbsolutePathName(desktop1);";
            string[] str = template.Split('/');
            string savename = "";
            for (int i = 0; i < str.Length; i++)
            {
                savename = str[i];
            }
            string process = HttpContext.Current.Session["process_id"].ToString();
            jScript += "var strFileName = '" + process + "_" + savename + "_" + DateTime.Now.ToString("ddMMyyyy") + ".doc';";
            jScript += "var strFullName = objFileObject.BuildPath(pathstring, strFileName);";
            jScript += "word.ActiveDocument.SaveAs(strFullName);";
            jScript += "var strFullName1 = objFileObject1.BuildPath(pathstring1, strFileName);";
            jScript += "word.ActiveDocument.SaveAs(strFullName1);";
            
           
            jScript += "obj.Close();word.Quit();";
            jScript += "alert(strFileName +' has been saved on your Pack folder.');";
            jScript += "}";// "window.location='" + redirect_url + "';}";
            jScript += "}catch(ex){alert(ex);}/*{window.location='../View/checkWord.aspx?pg=" + pg + "';}*/";


jScript + =</script>" ;;


jScript += "</script>";

推荐答案

原因是应用程序用户无权访问项目文件夹.提供对AppUser的访问权限后,它将可以正常使用.
Reason is that the application user doesn''t have the permission to the project folder. Once you provide the access to AppUser, it will perfectly work.


这篇关于将自动生成的文件保存到物理存档器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆