[RESOLVED]Not able to open a new page using javscript

I am uploading a doc file and want show this doc file in html .

For showing only i am using javscript function window,open but it is not opening 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Office;
using Microsoft.Office.Interop.Word;
using System.IO;

namespace docTohml
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected Microsoft.Office.Interop.Word.ApplicationClass objWord = new ApplicationClass();
//This creates new object of Word.ApplicationClass
protected string strPathToUpload;
//Path to upload files "Uploaded"
protected string strPathToConvert;
//Path to convert uploaded files and save
object fltDocFormat = 10;
//For filtered HTML Output
protected object missing = System.Reflection.Missing.Value;
//Is just to skeep the parameters which are passed as boject reference, these are seems to be optional parameters
protected object readOnly = false;
protected object isVisible = false;

protected void btnUpload_Click(object sender, EventArgs e)
{
//Code to check if user has selected any file on the form
if (!(fUpload.HasFile))
{
lblMessage.Text = "Please choose file to upload";
}
else
{
try
{
//To check the file extension if it is word document or something else
string strFileName = fUpload.FileName;
string[] strSep = fUpload.FileName.Split(‘.’);
int arrLength = strSep.Length – 1;
string strExt = strSep[arrLength].ToString().ToUpper();
//Save the uploaded file to the folder
strPathToUpload = Server.MapPath("Uploaded");
//Map-path to the folder where html to be saved
strPathToConvert = Server.MapPath("WordToHtml");
object FileName = strPathToUpload + "\" + fUpload.FileName;
object FileToSave = strPathToConvert + "\" + fUpload.FileName + ".htm";
if (strExt.ToUpper().Equals("DOC") || strExt.ToUpper().Equals("DOCX"))
{
fUpload.SaveAs(FileToSave.ToString());
lblMessage.Text = "File uploaded successfully";
//open the file internally in word. In the method all the parameters should be passed by object reference
objWord.Documents.Open(ref FileToSave, ref readOnly, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing,
ref missing, ref missing);
//Do the background activity
objWord.Visible = false;
Microsoft.Office.Interop.Word.Document oDoc = objWord.ActiveDocument;
oDoc.SaveAs(ref FileToSave, ref fltDocFormat, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing);
lblMessage.Text = fUpload.FileName + " converted to HTML successfully";
string g = FileToSave.ToString();

ClientScript.RegisterStartupScript(this.GetType(), "newpage", "<script type=’text/javascript’> window.open(‘" + g + "’ , "width=200, height=100");</script>", true);

}
else
{
lblMessage.Text = "Invalid file selected!";
}
//Close/quit word
objWord.Quit(ref missing, ref missing, ref missing);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
}
}

pls tell how correct my code 

Hi kaushiklotus,

Thanks for your post.

kaushiklotus

For showing only i am using javscript function window,open but it is not opening 

You could try the below code to open a new popup window from Server Side.

string url = "YourUrl";

ClientScript.RegisterStartupScript(this.GetType(), "script", "window.open('" + url + "', '', 'width=200,height=100');", true);

If you have any question about my reply, please let me know freely.

Best Regards,

Fei Han

Thanks 

But In new page is coming as blank 

Hi Kaushik,

you need to provide a url to window.open , like a path to where your html file is saved and you can give various other specifications too.

Please go through this link : http://www.w3schools.com/jsref/met_win_open.asp for more details.

Hope this helps

Hi kaushiklotus,

kaushiklotus

string g = FileToSave.ToString();

ClientScript.RegisterStartupScript(this.GetType(), "newpage", "<script type=’text/javascript’> window.open(‘" +
g + "’ , "width=200, height=100");</script>", true);

As for this problem, I agree with shivigupta. You should provide a url.

Best regards,

Fei Han

Leave a Reply