How to Save word document in a folder which is created by Directory.CreateDirectory(docfile_path)?

  • Thread starter Thread starter The Techie here
  • Start date Start date
T

The Techie here

Guest
I want to create a folder named as "test" inside this there will be
another folder named as today's date "date" , i want to keep the the
word document inside this date folder, please help.

This block of code throws an error called file name is invalid.

public string File_path;
public string docfile_path;
public string filename;

private void button1_Click(object sender, EventArgs e)
{

string time = DateTime.Now.ToString("HH.mm.ss");
string date = DateTime.Today.ToShortDateString();

docfile_path = File_path+ "test" + date;
Directory.CreateDirectory(docfile_path);

filename = docfile_path + "worddoc"+"-" +".docx";


Word.Application app = new Word.Application();
Word.Document doc = new Word.Document();
try
{
doc = app.Documents.Open(filename);
}
catch
{

}

Word.Paragraph oPara1;
oPara1 = doc.Content.Paragraphs.Add();
oPara1.Range.Text = "Test Result";
oPara1.Range.Font.Bold = 1;
oPara1.Format.SpaceAfter = 24;
oPara1.Range.InsertParagraphAfter();
oPara1.Range.InsertParagraphAfter();
Word.Paragraph oPara2;
oPara2 = doc.Content.Paragraphs.Add();
oPara2.Range.Text = "Test Name";
oPara2.Range.Font.Bold = 1;
oPara2.Format.SpaceAfter = 24;
oPara2.Range.InsertParagraphAfter();

doc.SaveAs2(filename);
doc.Close();
doc = null;

app.Quit();
app = null;

}

Continue reading...
 
Back
Top