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 += "}";
jScript += "}catch(ex){alert(ex);}/*{window.location='../View/checkWord.aspx?pg=" + pg + "';}*/";
jScript += "</script>";