34

I am getting this error Invalid temp directory in chart handler configuration [c:\TempImageFiles\]. While running my code.

Intially I was getting No http handler was found for request type ‘GET’ error which I solved it by referring no http handler

But now I am getting the above error The details of the error are

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.DirectoryNotFoundException: Invalid temp directory in chart handler configuration [c:\TempImageFiles\].

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

The stackTrace of this error

[DirectoryNotFoundException: Invalid temp directory in chart handler configuration [c:\TempImageFiles\].]
   System.Web.UI.DataVisualization.Charting.ChartHttpHandlerSettings.Inspect() +851
   System.Web.UI.DataVisualization.Charting.ChartHttpHandlerSettings.ParseParams(String parameters) +1759
   System.Web.UI.DataVisualization.Charting.ChartHttpHandlerSettings..ctor(String parameters) +619
   System.Web.UI.DataVisualization.Charting.ChartHttpHandler.InitializeParameters() +237
   System.Web.UI.DataVisualization.Charting.ChartHttpHandler.EnsureInitialized(Boolean hardCheck) +208
   System.Web.UI.DataVisualization.Charting.ChartHttpHandler.EnsureInstalled() +33
   System.Web.UI.DataVisualization.Charting.Chart.GetImageStorageMode() +57
   System.Web.UI.DataVisualization.Charting.Chart.Render(HtmlTextWriter writer) +257
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +144
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +583
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +91
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +410
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +118
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +489
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +84
   System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +713
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +144
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +583
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +91
   System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +91
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +410
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +118
   System.Web.UI.Control.Render(HtmlTextWriter writer) +60
   System.Web.UI.Page.Render(HtmlTextWriter writer) +66
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +144
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +583
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +91
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7761

Can anyone tell me how to solve this problem... Should i have to create a temporary directory manually or what should i do...


Hi smarx, I check it.. They asked me to change

From   
<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />

To
 <add key="ChartImageHandler" value="storage=file;timeout=20;" />

in web config file...

But I don't have this line in my web config

I have only this for defining chart

<add name="ChartImg" verb="*" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,     System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  />
<add name="ReportViewer" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler,Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

What should I do now....

1
  • Does that directory exists on your system? If so then does the user accessing the directory have privileges?
    – azamsharp
    Apr 18, 2010 at 4:02

11 Answers 11

51

You need to use a temporary directory that is within the folder hierarchy of your web application. In Windows Azure, you don't have access to c:\TempImages, so that is not going to work.

I created a quick sample of ASP.Net Charts working in Windows Azure here: http://code.msdn.microsoft.com/azurecharts

You can still use file storage for the temporary images:

If you don't want to download the sample, here are the steps to get it working:

  1. In your Solution, create a folder (called TempImages, for example).
  2. Add a file (temp.txt, or whatever) to this folder. The dev tools don't seem to publish empty directories.
  3. Set the image location of your chart to:

    ImageLocation="~/TempImages/ChartPic_#SEQ(300,3)"

  4. Add the following to appSettings in your web.config :

    <add key="ChartImageHandler" value="Storage=file;Timeout=20;Url=~/tempImages/;"/>

  5. Make sure the following is in system.web/assemblies :

    <add assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

  6. Make sure the following is in system.web/httpHandlers :
    <add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>

  7. Make sure the following is in system.webServer/handlers
    <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

The code I uploaded to code.msdn.com should suffice as an example.

4
  • I understand that the answer is general purpose, but I don't understand why it's being answered in the Azure context. I see nothing about Azure in the original question, so why did you bring that up? And, would the setting in "3" be different in a real site?
    – Jasmine
    Feb 20, 2012 at 18:26
  • 1
    The winner for me was using Url=~/tempImages/ rather than Dir=~/tempImages/ Jun 20, 2012 at 12:10
  • 2
    #Dan, thanks a lot for the solution. Somehow I only need 4 steps to correct this problem. They are 1 - 3 of yours plus: ImageStorageMode="UseImageLocation"
    – Hong
    Nov 26, 2012 at 2:22
  • 2
    Great reply. Just make sure that you give public R/W access to TempImages! Feb 14, 2014 at 16:51
15

try to add this key to your web.config

 <add key="ChartImageHandler" value="storage=file;timeout=20;" />

instead of the default one:

<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />
0
13

If changing the following line

<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />

to

<add key="ChartImageHandler" value="storage=file;timeout=20;" />

not works, then change the value of attribute "storage=file;" to "storage=memory;" . It will surely work because now you are using memory, instead of file.

5

Time still progresses and people still have recommendations. I came across this issue during a migration, so I thought I'd add my two cents.

Why store it in the file system and not just keep it in memory?

<add key="ChartImageHandler" value="storage=memory;deleteAfterServicing=true;"/>

If the file system is an issue in Azure, then don't use it.

4

Do the followings

1) Add or Edit the following key in web.config.

<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" /

2) Give writing privilages to IIS_User to this directory, for that do the followings:

a) Go to Windows Explorer.
b) Right click on c:\TempImageFiles Folder.
c) click Properties.
d) Select security tab , click Edit, click Add , Click Advanced, search for IIS_User.
e) Add this IIS_User , give write permission to this user.
f) Save and Close.

Now you have set the directory and given write permission to IIS to write temporary image files to this folder.

It should work now.

1
  • Thanks! solved........ In my case "TempImageFiles" was not copied to c drive, I created it and gave permission as above Oct 14, 2017 at 6:24
4

I had the same issue, my problem was my provider had special folders with write rights, so I changed the TempImagesFile folder to their default folder and it worked.

In my case the folder with write rights was called upload

web.config edits:

<appSettings>
    <add key="ChartImageHandler" value="Storage=file;Timeout=20;Url=~/upload/;"/>
</appSettings>

Hope this can help other too ;)

2

Update your app setting to this and see if that fixes your problem

 <appSettings>
    <add key="ChartImageHandler" value="storage=file;timeout=20;deleteAfterServicing=false;privateImages=false" />
    <add key="ChartImageHandler" value="storage=memory;deleteAfterServicing=true;"/>
  </appSettings>

1

Check out this answer on the Windows Azure forum: http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/92238582-9445-4d15-a5a7-5f24fd4bf646/.

0

You can circumvent temporary image caching by using BinaryStreaming.
Google should do the rest.
It worked for me on Linux, where it threw an InvalidDirectory Exception for Linux paths.

(RenderType="BinaryStreaming")

<asp:Chart ID="ChartDIN277" runat="server" Width="500" Height="200" RenderType="BinaryStreaming">
        <Series>
             <asp:Series ChartArea="ChartArea1" ChartType="Pie" 
                Name="Area" 
                XValueMember="Label" 
                YValueMembers="Area" 
                IsVisibleInLegend="false"> 
                </asp:Series> 
        </Series>
        <ChartAreas>
            <asp:ChartArea Name="ChartArea1">
                <Area3DStyle Enable3D="True" LightStyle="Realistic" />
            </asp:ChartArea>
        </ChartAreas>
</asp:Chart>

Codebehind:

protected void Page_Load(object sender, EventArgs e)
        {
            FillChartFromDataBase();
        }



        public void FillChartFromDataBase()
        {
            System.Data.DataTable table = new System.Data.DataTable();
            table.Columns.Add("Area", typeof(double));
            table.Columns.Add("Label", typeof(string));

            System.Data.DataRow row = table.NewRow();
            row["Area"] = 791;
            row["Label"] = "HNF 1";
            table.Rows.Add(row);

            row = table.NewRow();
            row["Area"] = 978;
            row["Label"] = "HNF 2";
            table.Rows.Add(row);

            row = table.NewRow();
            row["Area"] = 1262;
            row["Label"] = "HNF 3";
            table.Rows.Add(row);

            row = table.NewRow();
            row["Area"] = 1650;
            row["Label"] = "HNF 4";
            table.Rows.Add(row);

            row = table.NewRow();
            row["Area"] = 2519;
            row["Label"] = "HNF 5";
            table.Rows.Add(row);

            row = table.NewRow();
            row["Area"] = 6071;
            row["Label"] = "HNF 6";
            table.Rows.Add(row);


            // Set chart custom palette
            ChartDIN277.Palette = System.Web.UI.DataVisualization.Charting.ChartColorPalette.None;

            //ChartDIN277.PaletteCustomColors = New System.Drawing.Color() {System.Drawing.Color.Red, System.Drawing.Color.Blue}
            ChartDIN277.PaletteCustomColors = COR.Design.ColorPalette.Generate(System.Drawing.Color.ForestGreen, table.Rows.Count - 1);

            // http://student.csdn.net/space.php?uid=383581&do=blog&id=32768
            //ChartDIN277.Palette = System.Web.UI.DataVisualization.Charting.ChartColorPalette.None; 
            //ChartDIN277.PaletteCustomColors = new Color[] { System.Drawing.Color.Red, System.Drawing.Color.Blue};
            //// Hide all series empty data point by making them transparent
            //Chart.Series[0].EmptyPointStyle.Color = Color.Transparent; 
            //// Set color for the whole series
            //Chart.Series[0].Color = Color.Green;

            //// Set color of a single data point
            //Chart.Series[0].Points[5].Color = Color.Red;

            this.ChartDIN277.DataSource = table;
            this.ChartDIN277.DataBind();
        }




or create an ashx handler, like this

Imports System.Web
Imports System.Web.Services

Public Class ChartCreator
    Implements System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

        context.Response.ContentType = "image/jpeg"

        Dim yValues As Double() = {10, 27.5, 7, 12, 45.5}
        Dim xNames As String() = {"Mike", "John", "William", "George", "Alex"}


        Dim mychart As System.Web.UI.DataVisualization.Charting.Chart
        mychart = New System.Web.UI.DataVisualization.Charting.Chart
        Dim mychartarea As New System.Web.UI.DataVisualization.Charting.ChartArea()
        mychartarea.Name = "ChartArea1"
        mychartarea.BackColor = Drawing.Color.Transparent

        mychart.ChartAreas.Add(mychartarea)

        Dim myseries As New System.Web.UI.DataVisualization.Charting.Series()
        myseries.ChartArea = mychartarea.Name
        myseries.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie
        myseries.Name = "Series1"

        mychart.Series.Add(myseries)
        mychart.BackColor = Drawing.Color.Transparent

        mychart.Series(0).Points.DataBindXY(xNames, yValues)
        mychart.Series(0).Points.DataBindXY(xNames, yValues)


        ' http://msdn.microsoft.com/en-us/library/system.web.ui.datavisualization.charting.rendertype.aspx
        ' ImageTag, BinaryStreaming, ImageMap
        ' mychart.RenderType = System.Web.UI.DataVisualization.Charting.RenderType.BinaryStreaming

        mychart.ImageType = System.Web.UI.DataVisualization.Charting.ChartImageFormat.Png


        'mychart.SaveImage(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "mychart.png"))
        mychart.SaveImage(context.Response.OutputStream)


        'getResizedImage(context.Request.PhysicalPath,Width,Height);
        'context.Response.OutputStream
        context.Response.End()

    End Sub

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class
1
  • Yes, the ashx file creates only an image. You need to embed it in a page like this: <img src="ChartCreator.ashx?parameters" />. Also, in the ashx file, you need to declare the legend, header etc. if you want it. Feb 22, 2011 at 9:57
0

Just create a folder with name 'TempImageFiles' in C drive.

2
  • 1
    In a shared hosting environment you wouldn't have access to the C: drive.
    – Ed Graham
    Aug 24, 2012 at 16:43
  • thanks, this worked smoothly in my case because we have complete control over the server Aug 23, 2014 at 3:35
0

Here is a solution that we had to implement in our environment since we don't have control over our servers or have any ability to grant access to any folders and whatnot:

In our web.config we also changed our appSettings key to look like the following:

    <appSettings>
<add key="ChartImageHandler" value="storage=memory;timeout=20;" />

But where we did something different was down in our system.webServer/handlers section of our web.config. We did the following:

    <system.webServer>
        <handlers>
            <remove name="ChartImageHandler" />
            <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=<your application's public key token>" />
        </handlers>
    </system.webServer>

We had to go this route because the chart wasn't displaying anything but also wasn't error-ing out. Hope this possibly helps someone :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.