fileName = @"D:\test.html";
but if I do not include the filename 'test.html' it won't save the file. As the program is based on user input I want to extract the file path from the file open dialog and save the file respectively. Is there any possible way to do this? Also, I want to modify the code so the user can select multiple files to convert and save automatically, without having to list the filename in the source code.
Here is my file open code:
public void btnOpenFile_Click(object sender, System.EventArgs e)
{
this.fDialog = new OpenFileDialog();
fDialog.Filter = Properties.Resources.WordDoc;
fDialog.InitialDirectory = @"D:\input\";
fDialog.CheckFileExists = true;
fDialog.AddExtension = true;
fDialog.DefaultExt = "doc";
if (fDialog.ShowDialog() == DialogResult.OK)
{
sfileName = fDialog.FileName;
sPath = Path.GetFileName(fDialog.FileName);
if (sPath == String.Empty)
return;
}
}
Here is the problem code:
else if (result == DialogResult.Yes)
{
object fileName = sfileName;.
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document aDoc = new Microsoft.Office.Interop.Word.Document();
aDoc = app.Documents.Add(ref missing, ref missing, ref missing, ref missing);
app.Visible = true;
try
{
aDoc = app.Documents.Open(ref fileName, ref readOnly, ref missing, 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);
aDoc.Activate();
fileName = @"D:\test.html";
object fileformat = Word.WdSaveFormat.wdFormatFilteredHTML;
aDoc.SaveAs(ref fileName, ref fileformat, 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);
aDoc.Close(ref missing, ref missing, ref missing);

New Topic/Question
Reply
MultiQuote






|