Question

I am passing the page id component id and template id to a aspx page as querystring with this java script:

var masterTabControl = $controls.getControl($("#MasterTabControl"),
                                            "Tridion.Controls.TabControl");
p.compPresTab = masterTabControl.getPage("ComponentPresentationsTab");
p.selectedComponentPresentation = p.compPresTab.getSelectedComponentPresentation();

p.selectedComp = p.selectedComponentPresentation.getComponentId();

window.open("http://" + location.hostname + ":path/test.aspx?pgId=" + pageId + 
            "&comId=" + p.selectedComponentPresentation.getComponentId() + 
            "&comTmpId=" + 
            p.selectedComponentPresentation.getComponentTemplateId(), 
            "myWindow", "status = 1, 
            toolbar=no,width=300,height=200,resizable=no,scrollbars=yes");

Now on the test.aspx page i am reading the id and with some additional information from the user i am saving it into a text file.

On a button click on popup test.aspx page i am saving it in text file:

sLogDetails = PageId + "| " + ComponentId + "|" + ComponentTemplateId + 
              "|" + text ;

//Move the contents to the temp file other than the existing one.
using (var sr = new StreamReader(permanentFile))
{
    using (var sw = new StreamWriter(@"" + tempFile , true))
    {
        string line;

        while ((line = sr.ReadLine()) != null)
        {
            string[] parts = line.Split('|');
            PageId = parts[0].Trim();
            ComponentId = parts[1].Trim();
            ComponentTemplateId = parts[2].Trim();

            //Check there exist same record already 
            if (SPageId != PageId.Trim() || SComponentId != ComponentId.Trim() 
                || SComponentTemplateId != ComponentTemplateId.Trim())
                sw.WriteLine(line);
        }

        //Delete the Permanent file & create permanent file from temporary file
        File.Delete(permanentFile);
        File.Move(tempFile, permanentFile);


        // Insert changes to the Permanent file
        using (StreamWriter w = File.AppendText(permanentFile))
        {
            // Close the writer and underlying file.
            w.WriteLine(sLogDetails);
            w.Flush();
            w.Close();
        }

If the id is already present in the text file then i am populating it in the text field on popup test.aspx page like :

using (StreamReader r = File.OpenText(strPath + "Log.txt"))
{
    string line;

    while ((line = r.ReadLine()) != null)
    {
        // Console.WriteLine(line);
        string[] parts = line.Split('|');
        PageId=parts[0].Trim();
        ComponentId = parts[1].Trim();
        ComponentTemplateId = parts[2].Trim();

        //If there exist a record populate the data fields
       if (SPageId == PageId.Trim() && SComponentId == ComponentId.Trim() 
           && SComponentTemplateId == ComponentTemplateId.Trim())
        {
            txtRuleName.Text = (string)parts[3];
        }

    }
    r.Close();
}

Now I am getting stuck here. When it's populating in the text field, user can edit the text area in popup test.aspx page and on click of ok it will get saved in text file. And if user is closing the page window without "save & Close", then the changes made by him in text field should not get saved in text file. It should revert back to old one.

Any idea how can i make it?

Was it helpful?

Solution

It is fairly difficult to respond to "something that didn't happen".

So is there any way you can create a list of other ways that the user can exit that Window? With that list you can register the relevant event handlers (or override the relevant commands) and implement your roll back there.

Alternatively you can consider making the change to the file in a temporary location from your popup. And then only commit it to your text file when the user clicks Save and Close.


Note that his file-based approach will start failing when you scale out your Tridion GUI and Content Manager to run on multiple machines. In general you should be wary of storing things in files on a server, when you are working on enterprise level software. What is a single server now (and will always be a single server in your development environment) will turn into multiple servers at some point in the future at which time your solution will cause problems.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top