Hi RPA,
The process will be copy the server file into the local temp path and do the rest process from temp path and save in local and launch it.
protected void Page_Load(object sender, EventArgs e)
{
var serverFilePath = @"D:\docrep.docx";
// Temp path to save the file from server.
object destination = Server.MapPath("~/") + Path.GetFileName(serverFilePath);
// Check file exist in Server Path.
if (File.Exists(serverFilePath))
{
// Check file exist in temp Path.
if (File.Exists(destination.ToString()))
{
// Delete existing file from temp path.
File.Delete(destination.ToString());
}
// Copy file from server to Temp path.
File.Copy(serverFilePath, destination.ToString());
}
Word.Application word = new Word.Application();
Word.Document doc = new Word.Document();
object missing = System.Type.Missing;
try
{
// Open from Temp path.
doc = word.Documents.Open(ref destination, 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, ref missing);
doc.Activate();
foreach (Microsoft.Office.Interop.Word.Range docRange in doc.Words)
{
if (docRange.Text.Trim() == "#")
{
docRange.Text = docRange.Text.Replace("#", "");
}
else if (docRange.Text.Trim() == "Pr")
{
docRange.Text = docRange.Text.Replace("Pr", "5.0");
}
else if (docRange.Text.Trim() == "n")
{
docRange.Text = docRange.Text.Replace("n", "0001");
}
else if (docRange.Text.Trim() == "nm")
{
docRange.Text = docRange.Text.Replace("nm", "Rustam");
}
else if (docRange.Text.Trim() == "brth")
{
docRange.Text = docRange.Text.Replace("brth", "22.12.1987");
}
}
// local computer address.
string filePath = @"C:\direction.docx";
if (File.Exists(filePath))
{
File.Delete(filePath);
}
// Save updated doc in local computer.
doc.SaveAs(filePath, missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing);
Process.Start("WINWORD.EXE", "\"" + filePath + "\"");
}
catch { }
finally
{
doc.Close(ref missing, ref missing, ref missing);
((Word._Application)word).Quit();
if (File.Exists(destination.ToString()))
{
// Delete copied file from temp path.
File.Delete(destination.ToString());
}
}
}
If you are using ftp server refer below link to copy file.