Click here to Skip to main content
14,921,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.






C#
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>";
Posted

1 solution

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.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900