locked
throw new NotImplementedException error RRS feed

  • Question

  • User-605499000 posted

    I need to get rid of not Implemented exception in my default file. When I take it out the Load files does not work.  I had to change the stream reader and that is when the problem started. This is the default page that opens a magazine in javascript, so I need a stream reader.I put in System IO and changed the stream reader to class test.  When I try to open the file on the web I get the error not to use Not Implemented. When I take it out the load files does not work.

    I  hope someone has an answer to this problem.  Thanks Jen

    Below is the file:

    using System;
    using System.IO;
    using System.Web.UI;

    namespace Bumples
    {
    public partial class GamesB_Default : UI.BasePage
    {
    private Int32 issue = 0;
    private String section = "";

    public GamesB_Default()
    {
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    //
    if (String.IsNullOrEmpty(this.Request.QueryString["Issue"]))
    {
    this.issue = 1;
    //throw new SecurityException("Error loading Issue!");
    }
    else
    {
    try
    {
    this.issue = Int32.Parse(this.Request.QueryString["Issue"]);
    }
    catch
    {

    this.issue = 1;
    }
    }

    if (issue < 1 || issue > 38)
    {
    issue = 1;
    //throw new SecurityException("Error loading Issue!");
    }

    //
    if (String.IsNullOrEmpty(this.Request.QueryString["Section"]))
    this.section = "";
    else
    this.section = this.Request.QueryString["Section"];

    if (this.IssueName() == "Issue002" || this.IssueName() == "Issue003" || this.IssueName() == "Issue004" || this.IssueName() == "Issue008")
    {
    if (this.User.Identity.IsAuthenticated && (
    this.User.IsInRole("SuperAdministrator") ||
    this.User.IsInRole("Administrators") ||
    this.User.IsInRole("Issue002") || this.User.IsInRole("Issue003") || this.User.IsInRole("Issue004") || this.User.IsInRole("Issue008") ||
    this.User.IsInRole("Subscriber")))

    {
    ;
    }
    else
    {
    //String page = System.Web.HttpContext.Current.Request.Url.AbsoluteUri; // this.GetCurrentPageName();
    //this.RequestLogin();
    //Response.Redirect("~/Subscribe.aspx");
    //throw new SecurityException("You are not allowed to edit existent articles!");
    }
    }

    /* Execute */
    this.LoadJavaScript();
    /* Execute */
    }

    private void LoadJavaScript()
    {
    String javaScript = "";

    javaScript += LoadFile("~/Issues/JavaScript/Movime.js");
    javaScript += LoadFile("~/Issues/JavaScript/DivClass.js");
    javaScript += LoadFile("~/Issues/JavaScript/TalkingBalloon.js");
    javaScript += LoadFile("~/Issues/JavaScript/Magazine.js");
    javaScript += LoadFile("~/Issues/JavaScript/PuzzleClass.js");
    javaScript += LoadFile("~/Issues/JavaScript/MemoryClass.js");
    javaScript += LoadFile("~/Issues/JavaScript/MoveObjectsTo.js");
    javaScript += LoadFile("~/Issues/JavaScript/gamet.js");
    javaScript += LoadFile("~/Issues/" + this.IssueName() + "/JavaScript.js");

    Page.ClientScript.RegisterStartupScript(this.GetType(), "", javaScript, true);
    }

    public String LoadCss()
    {
    return "<style type=\"text/css\"> " + LoadFile("~/Issues/" + this.IssueName() + "/CssStyles.css") + " </style>";
    }

    private string LoadFile(string v)
    {
    throw new NotImplementedException();  (#Error when I take it out then the load files show errors and will not load. I have tried putting other things there but nothing works)
    }

    private String IssueName()
    {
    return "Issue" + ((this.issue < 100) ? "0" : "") + ((this.issue < 10) ? "0" : "") + this.issue.ToString().Trim() + this.section;
    }

    class test
    {
    public static void Main()
    {
    try
    {
    // Create an instance of StreamReader to read from a file.
    // The using statement also closes the StreamReader.
    using (StreamReader sr = new StreamReader("TestFile.txt"))
    {
    string line;
    // Read and display lines from the file until the end of
    // the file is reached.
    while ((line = sr.ReadLine()) != null)
    {
    Console.WriteLine(line);
    }
    }
    }
    catch (Exception e)
    {
    // Let the user know what went wrong.
    Console.WriteLine("The file could not be read:");
    Console.WriteLine(e.Message);
    }
    }
    }

    protected void Page_Render(object sender, EventArgs e)
    {
    //
    // Insert JavaScript for Image Upload Completed (Flash object will call this function when finished)
    //
    try
    {
    //LinkButton lb = (LinkButton)FormViewItem.Row.FindControl("LinkButtonProcessUpload");
    //LinkButton lb = (LinkButton)RepeaterInfo.Items[0].FindControl("LinkButtonProcessUpload");
    //HiddenField hf = (HiddenField)FormViewItem.Row.FindControl("FlashArguments");
    //HiddenField hf = (HiddenField)RepeaterInfo.Items[0].FindControl("FlashArguments");

    String javaScript = "function UploadComplete() {";

    //javaScript += String.Format("var hiddenFieldObj = document.getElementById('{0}');", hf.ClientID.Replace("_", "$"));
    //javaScript += " if (hiddenFieldObj != null && _args != null)";
    //javaScript += " {";
    //javaScript += " hiddenFieldObj.value = _args;";
    //javaScript += " alert(_args);";
    //javaScript += " }";
    //javaScript += " ";
    javaScript += String.Format("__doPostBack('{0}', '' );", "var a=0;");
    javaScript += "};";

    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "FileCompleteUpload", javaScript, true);
    }
    catch
    { }
    }
    }
    }

    Monday, January 21, 2019 9:07 PM

Answers

  • User-605499000 posted

    Thank you very much for your help. That did not work but I went back to the file that was used in 2009 and was able to fix the problem.

    Again thanks for your time.

    Jen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 22, 2019 10:50 PM
  • User-605499000 posted

    Thank you very much for your help. I finally solved it by going back to the original file in 2009  and restarted it made some changes and it is working. I learned a lot today from you and try to resolve the problem. Again, I thank you for your invaluable time.

    Jen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 22, 2019 10:53 PM

All replies

  • User753101303 posted

    Hi,

    Show rather the code that you expect to work and that doesn't. My guess is that in LoadFile you tried to use a stream reader but as you pass a virtual path, you likely should use Server.MapPath so that you can open the proper file.

    You want to concatenate all those scripts ? You could try:

    private string LoadFile(string v)
    {
       //throw new NotImplementedException();
       return System.IO.File.ReadAllText(Server.MapPath(v));
    }

    Monday, January 21, 2019 10:10 PM
  • User-893317190 posted

    Hi bumples18,

    Since your script javaScript: Movime.js,DivClass.js,TalkingBalloon.js,Manazine.js,PuzzleClass.js,MovieObjectsTo.js and gamet.js is always in your page, why not move the reference to your aspx page.

    <script src="/Issues/JavaScript/Movime.js"></script>

    As to your dynamic javascript "~/Issues/" + this.IssueName() + "/JavaScript.js",when dealing with reading file, you should get the Absolute path of your file in the file system instead of relative path to your project such as new StreamReader("TestFile.txt")), or it will read file from 'C:\Program Files\IIS Express\ if you use iis express.

    Best regards,

    Ackerly Xu

    Tuesday, January 22, 2019 2:57 AM
  • User-605499000 posted

    I have tried everything and can't seem to resolve the problem. I just put back the original steam reader and tried to put it in the systemIO but that did not work.

    The error is now  a server error could not find a part of the path.  It use to work in the old program so can we make a change here where it reads the system IO?  The one I put in yesterday the test keeps taking me back to the NotImplemented exception error and Microsoft says not to use that and I tried other exceptions that also did not work. I did move the javascript files to the aspx and that part is fine.  Below is the file changes that I made. I hope again you can help me. Jen  

    I do not have system IIS should I.

    using System;
    using System.IO;
    using System.Runtime.Serialization;
    using System.Web.UI;

    namespace Bumples
    {
    public partial class GamesB_Default : UI.BasePage
    {
    private Int32 issue = 0;
    private String section = "";

    protected void Page_Load(object sender, EventArgs e)
    {
    //
    if (String.IsNullOrEmpty(this.Request.QueryString["Issue"]))
    {
    this.issue = 1;
    //throw new SecurityException("Error loading Issue!");
    }
    else
    {
    try
    {
    this.issue = Int32.Parse(this.Request.QueryString["Issue"]);
    }
    catch
    {

    this.issue = 1;
    }
    }

    if (issue < 1 || issue > 25)
    {
    issue = 1;
    //throw new SecurityException("Error loading Issue!");
    }

    //
    if (String.IsNullOrEmpty(this.Request.QueryString["Section"]))
    this.section = "";
    else
    this.section = this.Request.QueryString["Section"];

    if (this.IssueName() == "Issue002" || this.IssueName() == "Issue003" || this.IssueName() == "Issue004" || this.IssueName() == "Issue008")
    {
    if (this.User.Identity.IsAuthenticated && (
    this.User.IsInRole("SuperAdministrator") ||
    this.User.IsInRole("Administrators") ||
    this.User.IsInRole("Issue002") || this.User.IsInRole("Issue003") || this.User.IsInRole("Issue004") || this.User.IsInRole("Issue008") ||
    this.User.IsInRole("Subscriber")))

    {
    ;
    }
    else
    {
    //String page = System.Web.HttpContext.Current.Request.Url.AbsoluteUri; // this.GetCurrentPageName();
    //this.RequestLogin();
    //Response.Redirect("~/Subscribe.aspx");
    //throw new SecurityException("You are not allowed to edit existent articles!");
    }
    }

    /* Execute */
    this.LoadJavaScript();
    /* Execute */
    }

    private void LoadJavaScript()
    {
    String javaScript = "";

    javaScript += LoadFile("~/Issues/" + this.IssueName() + "/JavaScript.js");

    Page.ClientScript.RegisterStartupScript(this.GetType(), "", javaScript, true);
    }

    public String LoadCss()
    {
    return "<style type=\"text/css\"> " + LoadFile("~/Issues/" + this.IssueName() + "/CssStyles.css") + " </style>";
    }

    private String IssueName()
    {
    return "Issue" + ((this.issue < 100) ? "0" : "") + ((this.issue < 10) ? "0" : "") + this.issue.ToString().Trim() + this.section;
    }

    private String LoadFile(String fileName)
    {
    //Open a file for reading
    fileName = Server.MapPath(fileName);

    //Get a StreamReader class that can be used to read the file
    StreamReader objStreamReader = File.OpenText(fileName);

    //Now, read the entire file into a string
    String fileContent = objStreamReader.ReadToEnd();

    objStreamReader.Close();

    return fileContent;
    }
    /*
    protected void Page_Render(object sender, EventArgs e)
    {
    //
    // Insert JavaScript for Image Upload Completed (Flash object will call this function when finished)
    //
    try
    {
    //LinkButton lb = (LinkButton)FormViewItem.Row.FindControl("LinkButtonProcessUpload");
    //LinkButton lb = (LinkButton)RepeaterInfo.Items[0].FindControl("LinkButtonProcessUpload");
    //HiddenField hf = (HiddenField)FormViewItem.Row.FindControl("FlashArguments");
    //HiddenField hf = (HiddenField)RepeaterInfo.Items[0].FindControl("FlashArguments");

    String javaScript = "function UploadComplete() {";

    //javaScript += String.Format("var hiddenFieldObj = document.getElementById('{0}');", hf.ClientID.Replace("_", "$"));
    //javaScript += " if (hiddenFieldObj != null && _args != null)";
    //javaScript += " {";
    //javaScript += " hiddenFieldObj.value = _args;";
    //javaScript += " alert(_args);";
    //javaScript += " }";
    //javaScript += " ";
    javaScript += String.Format("__doPostBack('{0}', '' );", "var a=0;");
    javaScript += "};";

    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "FileCompleteUpload", javaScript, true);
    }
    catch
    { }
    }

    public override bool Equals(object obj)
    {
    return Equals(obj as GamesB_Default);
    }

    public bool Equals(GamesB_Default other)
    {
    return other != null &&
    issue == other.issue &&
    section == other.section;
    }
    */
    }

    [Serializable]
    internal class NotFoundException : Exception
    {
    public NotFoundException()
    {
    }

    public NotFoundException(string message) : base(message)
    {
    }

    public NotFoundException(string message, Exception innerException) : base(message, innerException)
    {
    }

    protected NotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
    {
    }
    }
    }

    Tuesday, January 22, 2019 7:33 PM
  • User-605499000 posted

    Mistake, I do have IIS express and you are correct it does go to it.

    Tuesday, January 22, 2019 8:25 PM
  • User-605499000 posted

    Thank you very much for your help. That did not work but I went back to the file that was used in 2009 and was able to fix the problem.

    Again thanks for your time.

    Jen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 22, 2019 10:50 PM
  • User-605499000 posted

    Thank you very much for your help. I finally solved it by going back to the original file in 2009  and restarted it made some changes and it is working. I learned a lot today from you and try to resolve the problem. Again, I thank you for your invaluable time.

    Jen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 22, 2019 10:53 PM