0

I have 5 files in Excel. I want to change at one time the Data Source in Connection String using MVC.

In my controller:

public ActionResult ChangeExcelConnection()
        {
            ViewBag.Message = "Change connection.";
            return View();
        }

In ChangeExcelConnection.cshtml I want to enter name of data source.

@using System.Web.Mvc;
@{
    ViewBag.Title = "ChangeExcelConnection";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>@ViewBag.Message</h2>

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <div class="editor-label">Enter the name of the data source:</div>
        <div class="editor-field">
            @Html.TextArea("source")  
        </div><br>

        <p>
            <input type="submit" value="Save changes" />
        </p>
    </fieldset>
}

And I don't know how to change in controller files properties.

    [HttpPost]
    public ActionResult ChangeExcelConnection(String source)
    {
        DirectoryInfo directory = new DirectoryInfo(Server.MapPath("~/Excels"));
        var filesListing = directory.GetFiles("*.xlsm", SearchOption.AllDirectories);

    //???
    }

Do you have any idea how to do this and it is possible at all?

With regards,
Monica

Monic
  • 726
  • 10
  • 31
  • What kind of value is there in the source parameter ? The file name ? You want to find a file by its name ? – Dude Pascalou Jun 06 '14 at 13:10
  • It will be String - instance's name of SQL server. Here I have a code how to do that in VBA, but I want to do this in asp .net mvc http://stackoverflow.com/questions/20114223/modify-an-embedded-connection-string-in-microsoft-excel-macro – Monic Jun 06 '14 at 13:28
  • You want to change an Sql-Server connection string defined inside an Excel file macro ? – Dude Pascalou Jun 06 '14 at 13:43
  • I want to change Sql-Server connection string defined inside an Excel file but without using macro, just through my app. – Monic Jun 06 '14 at 13:45
  • Usually, you can use Office Interop to handle Excel, but it is not recommended on a web server. There are other API that can also manipulate Excel. You may search for them. – Dude Pascalou Jun 06 '14 at 14:02
  • So I shouldn't use sth like this? http://stackoverflow.com/questions/7268194/change-excel-external-data-connection-string Why is it not recommended on a web server? – Monic Jun 06 '14 at 18:10
  • No, you shouldn't. More information on considerations for server-side automation of Office : http://support.microsoft.com/kb/257757 – Dude Pascalou Jun 06 '14 at 20:46

0 Answers0