Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8097991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:56:06+00:00 2026-06-05T21:56:06+00:00

the variable doc is not accessible anywhere else in the method outside of the

  • 0

the variable “doc” is not accessible anywhere else in the method outside of the if statement so that if doc==null fails since the scope of “doc” is only within those if statements that it is defined in….How do I deal with this issue? adding public just leads to more errors..

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string id, type, UniqueColID;
            string FilePath = Server.MapPath("~").ToString();
            type = Request.QueryString["type"];

            if (type.Equals("template"))
            {
                MergeDocument template = new MergeDocument(FilePath + @"\Template\MVCTemplate.pdf");
                template.DrawToWeb();
            }
            else
            {
                id = Request.QueryString["id"];
                UniqueColID = DBFunctions.DBFunctions.testExist(id);
                if (DBFunctions.DBFunctions.FlagDriverPrintOnly == false)
                {
                    MergeDocument doc = PDF.LongFormManipulation.generatePDF(id, type, FilePath, UniqueColID);
                }
                else if (DBFunctions.DBFunctions.FlagDriverPrintOnly == true)
                {
                    MergeDocument doc = PDF.LongFormManipulation.generatePDFDriverOnly(id, type, FilePath, UniqueColID);
                }
                DBFunctions.DBFunctions.FlagDriverPrintOnly = false;
                    if (doc == null)
                    doc = new MergeDocument(FilePath + @"\Template\MVCTemplate.pdf");

                doc.DrawToWeb();
            }
        }
        catch(Exception err)
        {
            MessageBox("Creating PDF file was not successful. " + err.ToString());
        }

I have tried declaring it at higher level but I still get same error:

**Use of unassigned local variable 'doc' -->>>at: if (doc==nul)**   

After doing MergeDocument=null; at higher level I get a new error:

System.NullReferenceException: Object reference not set to an instance of an object. at GeneratePDF.Page_Load(Object sender, EventArgs e)

this error points to "if (type.Equals("template"))"

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:56:09+00:00Added an answer on June 5, 2026 at 9:56 pm

    Define the doc variable just before you actually want to use it:

    MergeDocument doc = null;
    if (DBFunctions.DBFunctions.FlagDriverPrintOnly == false) 
    { 
        doc = PDF.LongFormManipulation.generatePDF(id, type, FilePath, UniqueColID); 
    } 
    else if (DBFunctions.DBFunctions.FlagDriverPrintOnly == true) 
    { 
        doc = PDF.LongFormManipulation.generatePDFDriverOnly(id, type, FilePath, UniqueColID); 
    } 
    DBFunctions.DBFunctions.FlagDriverPrintOnly = false; 
    if (doc == null)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Variable outside of the loop int number = 0; for(int i = 0; i
I keep a Session variable when the user is logged in. So that when
I have a variable foo that contains a time, lets say 4pm today, but
I have xml document in variable (not in file). How can i get data
While reading from a site a read that you can not make a global
I have a variable that indicates the length of time the UI can be
I have a javascript file with a global object that must not be renamed
I have a select statement that I am trying to loop over and increment
Here is the scenario. I have an file outside of my Grails application that
Related, but not a fix: jQuery issue - #<an Object> has no method I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.