Translate

Home > 2013

2013

Sys.Extended is undefined (AjaxControlToolkit asp.net)

Tuesday, November 5, 2013 Category : 2

if u get this type 'Sys.Extended is undefined ' error in asp.net AjaxControlToolkit latest version on (4.1.7.1005)

use Ajaxtoolkit script manager not <asp:ScriptManager>

  <ajaxToolkit:ToolkitScriptManager EnablePartialRendering="true" runat="Server" ID="ScriptManager1" />




ASP.NET open a new window with asynchronous post back

Monday, September 30, 2013 Category : 0

asp.net open a new window using java


[Serializable]
    public class Result : System.Web.UI.Page
    {

public void showReportModified(string pageUrl, string param, Type cType, Page oPage,Control ctrl)
        {
 ScriptManager.RegisterStartupScript(ctrl, typeof(string), "redirect", "window.open('" + url + "');", true);
}

}


in your web page c# code where you open to a new window

protected void btnSave_Click(object sender, EventArgs e)
    {
new Result().showReportModified("url", "parameter" , this.GetType(), this.Page, UpdatePanel1);
}

ASP.NET MVC 4 , Ajax Image Upload

Sunday, August 25, 2013 Category : 1

<tr>
                    <th>
                        @Html.LabelFor(m => m.NewsBody)
                    </th>
                     <td>
                        @Html.TextAreaFor(m => m.NewsBody, new { @class = "my-textBox" })
                        @Html.ValidationMessageFor(m => m.NewsBody)
                    </td>
                </tr>


<script type="text/javascript">

    // Call this function on upload button click after user has selected the file
    function UploadFile() {
        var file = document.getElementById('etlfileToUpload').files[0];
        if(file == null) {return;}
        var fileName = file.name;
        var fd = new FormData();
        fd.append("fileData", file);
        var xhr = new XMLHttpRequest();
        xhr.upload.addEventListener("progress", function (evt) { UploadProgress(evt); }, false);
        xhr.addEventListener("load", function (evt) { UploadComplete(evt); }, false);
        xhr.addEventListener("error", function (evt) { UploadFailed(evt); }, false);
        xhr.addEventListener("abort", function (evt) { UploadCanceled(evt); }, false);
        xhr.open("POST", "/AP/FileUpload", true);
        xhr.send(fd);
    }


    function UploadProgress(evt) {
        if (evt.lengthComputable) {
            var percentComplete = Math.round(evt.loaded * 100 / evt.total);
            $("#uploading").text(percentComplete + "% ");
        }
    }

    function UploadComplete(evt) {
        if (evt.target.status == 200){
            //alert(evt.target.responseText);
            $("#uploading").text("Upload Success");
            $(".path").text(evt.target.responseText);
            document.getElementById('etlfileToUpload').parentNode.innerHTML = document.getElementById('etlfileToUpload').parentNode.innerHTML;

            }
        else {
            $("#uploading").text("Error Uploading File");
            //alert("Error Uploading File");
        }
    }

    function UploadFailed(evt) {
        alert("There was an error attempting to upload the file.");
    }

    function UploadCanceled(evt) {
        alert("The upload has been canceled by the user or the browser dropped the connection.");
    }

</script>






 [HttpPost]
        public JsonResult FileUpload(HttpPostedFileBase fileData)
        {
            string path = "";
            if (fileData != null)
            {
                string pic = System.IO.Path.GetFileName(fileData.FileName);
                path = System.IO.Path.Combine(Server.MapPath("~/news.resource"), pic);
                // file is uploaded
                fileData.SaveAs(path);
                path = pic;
                // save the image path path to the database or you can send image directly to database
                // in-case if you want to store byte[] ie. for DB
                /*using (MemoryStream ms = new MemoryStream())
                {
                    fileData.InputStream.CopyTo(ms);
                    byte[] array = ms.GetBuffer();
                }*/

            }
            // after successfully uploading redirect the user
            return Json(path);
            //return RedirectToAction("actionname", "controller name");
        }

State Management in ASP.NET

Friday, June 28, 2013 Category : 0

Types of state management  

There are two types of state management techniques: client side and server side.

Client side

  1. Hidden Field
  2. View State
  3. Cookies
  4. Control State
  5. Query Strings

Server side

  1. Session
  2. Application

Levels of state management 

  1. Control level: In ASP.NET, by default controls provide state management automatically.
  2. Variable or object level: In ASP.NET, member variables at page level are stateless and thus we need to maintain state explicitly.
  3. Single or multiple page level: State management at single as well as multiple page level i.e., managing state between page requests.
  4. User level: State should be preserved as long as a user is running the application.
  5. Application level: State available for complete application irrespective of the user, i.e., should be available to all users.
  6. Application to application level: State management between or among two or more applications.

Client side methods

1. Hidden field

Hidden field is a control provided by ASP.NET which is used to store small amounts of data on the client. It store one value for the variable and it is a preferable way when a variable's value is changed frequently. Hidden field control is not rendered to the client (browser) and it is invisible on the browser. A hidden field travels with every request like a standard control’s value.
Let us see with a simple example how to use a hidden field. These examples increase a value by 1 on every "No Action Button" click. The source of the hidden field control is.



<asp:HiddenField ID="HiddenField1" runat="server"  /> 
 

2. View state

View state is another client side state management mechanism provided by ASP.NET to store user's data, i.e., sometimes the user needs to preserve data temporarily after a post back, then the view state is the preferred way for doing it. It stores data in the generated HTML using hidden field not on the server.
View State provides page level state management i.e., as long as the user is on the current page, state is available and the user redirects to the next page and the current page state is lost. View State can store any type of data because it is object type but it is preferable not to store a complex type of data due to the need for serialization and deserilization on each post back. View state is enabled by default for all server side controls of ASP.NET with a property EnableviewState set to true.
Let us see how ViewState is used with the help of the following example. In the example we try to save the number of postbacks on button click.

3. Cookies

Cookie is a small text file which is created by the client's browser and also stored on the client hard disk by the browser. It does not use server memory. Generally a cookie is used to identify users.
A cookie is a small file that stores user information. Whenever a user makes a request for a page the first time, the server creates a cookie and sends it to the client along with the requested page and the client browser receives that cookie and stores it on the client machine either permanently or temporarily (persistent or non persistence). The next time the user makes a request for the same site, either the same or another page, the browser checks the existence of the cookie for that site in the folder. If the cookie exists it sends a request with the same cookie, else that request is treated as a new request.

Types of Cookies

1. Persistence Cookie: Cookies which you can set an expiry date time are called persistence cookies. Persistence cookies are permanently stored till the time you set.
Let us see how to create persistence cookies. There are two ways, the first one is: 


Response.Cookies["nameWithPCookies"].Value = "This is A Persistance Cookie";
Response.Cookies["nameWithPCookies"].Expires = DateTime.Now.AddSeconds(10); 
 


2. Non-Persistence Cookie: Non persistence cookies are not permanently stored on the user client hard disk folder. It maintains user information as long as the user accesses the same browser. When user closes the browser the cookie will be discarded. Non Persistence cookies are useful for public computers.
Let us see how to create a non persistence cookies. There are two ways, the first one is:
Response.Cookies["nameWithNPCookies"].Value = "This is A Non Persistance Cookie";
 
 

4. Control State

Control State is another client side state management technique. Whenever we develop a custom control and want to preserve some information, we can use view state but suppose view state is disabled explicitly by the user, the control will not work as expected. For expected results for the control we have to use Control State property. Control state is separate from view state.
How to use control state property: Control state implementation is simple. First override the OnInit() method of the control and add a call for the Page.RegisterRequiresControlState() method with the instance of the control to register. Then override LoadControlState and SaveControlState in order to save the required state information.


Server side

1. Session   

Session management is a very strong technique to maintain state. Generally session is used to store user's information and/or uniquely identify a user (or say browser). The server maintains the state of user information by using a session ID. When users makes a request without a session ID, ASP.NET creates a session ID and sends it with every request and response to the same user.
How to get and set value in Session:
 
void Session_Start(object sender, EventArgs e)
{
 
} 

Session["Count"] = Convert.ToInt32(Session["Count"]) + 1;//Set Value to The Session
Label2.Text = Session["Count"].ToString(); //Get Value from the Sesion


There are four session storage mechanisms provided by ASP.NET:
  • In Proc mode 
  • State Server mode  
  • SQL Server mode 
  • Custom mode
 
In Process mode: In proc mode is the default mode 
provided by ASP.NET. 
In this mode, session values are stored in the web server's memory (in 
IIS). 
If there are more than one IIS servers then session values are stored in
 each server separately on which request has been made. Since the 
session values 
are stored in server, 
whenever server is restarted the session values will be lost. 

<configuration>
 <sessionstate mode="InProc" cookieless="false" timeout="10" 
    stateConnectionString="tcpip=127.0.0.1:80808" 
    sqlConnectionString="Data Source=.\SqlDataSource;User ID=userid;Password=password"/>
</configuration> 
 
In State Server mode: This mode could store session in the web server but out of 
the application pool. But usually if this mode is used there will 
be a separate server for storing sessions, i.e., stateServer. The benefit is that when IIS restarts the session is available. 
It stores session in a separate 
Windows service. For State server session mode, we have to configure it explicitly in the web config file and start the aspnet_state service. 
 
If you having this problem in IIS 7.x; you can fix this issue with enabling “ASP.NET State Service” from the services. To do so; Follow the bellow steps:
1) Start–> Administrative Tools –> Services
2) Write click over the service shown below and click “start”

 

<configuration><sessionstate mode="stateserver" cookieless="false" 
   timeout="10"  stateConnectionString="tcpip=127.0.0.1:42424"  
   sqlConnectionString="Data Source=.\SqlDataSource;User ID=userid;Password=password"/> </configuration> 
 
 
 
In SQL Server mode: Session is stored in a SQL Server database. 
This kind of session mode is also separate from IIS, i.e., session 
is available even after restarting the IIS server. This mode is highly secure and reliable but also has a disadvantage that 
there is overhead from serialization 
and deserialization of session data. This mode should be used when reliability is more important than performance. 
 
aspnet_regsql.exe -ssadd -d ASPState -sstype c -S (local) -U sa -P sa123
 
<configuration>
    <sessionstate mode="sqlserver" cookieless="false" timeout="10" 
       stateConnectionString="tcpip=127.0.0.1:4  2424" 
       sqlConnectionString="Data Source=.\SqlDataSource;User ID=userid;Password=password"/>
</configuration> 


Custom Session mode: Generally we should prefer in proc
 state server mode or 
SQL Server mode but if you need to store session data using other 
than these techniques then ASP.NET provides a custom session mode. This 
way we have to maintain everything customized even generating session 
ID, data store, and also security. 


2. Application

Application state is a server side state management technique. The date stored in application state is common for all users of that particular ASP.NET application and can be accessed anywhere in the application. It is also called application level state management. Data stored in the application should be of small size.
How to get and set a value in the application object:
Application["Count"] = Convert.ToInt32(Application["Count"]) + 1; //Set Value to The Application Object
Label1.Text = Application["Count"].ToString(); //Get Value from the Application Object 
 
 
 
SSource : Code Project 

ASP.NET sub Repater (repater inside repater, nested) data source get from parent repater value

Wednesday, June 19, 2013 Category : 0

 <asp:Repeater ID="submenu1" runat="server" DataSource='<%# getSubCategory(DataBinder.Eval(Container.DataItem,"ID").ToString()) %>'>
                                <ItemTemplate>
                                <li>
                                    <asp:HyperLink ID="lnkMenuItem" runat="server" NavigateUrl='<%# "~/GUI/SubCategoryUI.aspx?Val=" + Eval("ID") + "&CategoryID=" + Eval("CategroyID") %>' Text='<% #Eval("SubCategroyName") %>'> </asp:HyperLink>
                                </li>
                                </ItemTemplate>
                            </asp:Repeater>

crdb_adoplus.dll' or one of its dependencies. The system cannot find the file specified.

Thursday, March 21, 2013 Category : , 0

<startup useLegacyV2RuntimeActivationPolicy="true" >
    <supportedruntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
 

Add this code in app.config. 

WCF wsHttpBinding sample configaration

Sunday, February 17, 2013 Category : 0

Service Config Sample

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime executionTimeout="90800" maxRequestLength="2147483647" />
  </system.web>

  <connectionStrings>
    <clear/>
    <!--<add name="MT_ConnectionString"
      connectionString="Data Source=DATASRV;Initial Catalog=report;Persist Security Info=True;User ID=me;Password=Me2012"
      providerName="System.Data.SqlClient" />-->
    <add name="MT_ConnectionString"
      connectionString="Data Source=PGTONMOY-PC\NOKIA;Initial Catalog=HShopMT;Persist Security Info=True;User ID=sa;Password=data"
      providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.serviceModel>
    <services>
      <service name="MT_WService.MTService" behaviorConfiguration="ServiceBehavior">
        <!-- Service Endpoints -->
        <endpoint address="MTService" behaviorConfiguration="EndPointBehavior" binding="wsHttpBinding"
            contract="MT_WService.IMTService" bindingConfiguration="WSHttpBinding_IMTService">
          <identity>
            <dns value="apps.mediasoftbd.com" />
          </identity>
        </endpoint>
        <!-- This Endpoint is used for genertaing the proxy for the client -->
        <!-- To avoid disclosing metadata information, set the value below to false and
       remove the metadata endpoint above before deployment -->
        <endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding" />
        <host>
          <baseAddresses>
            <add baseAddress="http://127.0.0.1/MTService/"/>
          </baseAddresses>
        </host>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="1909600"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="EndPointBehavior">
          <dataContractSerializer maxItemsInObjectGraph="1909600"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IMTService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:50:00" sendTimeout="00:50:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2000000000" maxReceivedMessageSize="2000000000" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <reliableSession ordered="true" inactivityTimeout="00:50:00" enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
            <message clientCredentialType="Windows" negotiateServiceCredential="false" algorithmSuite="Default" establishSecurityContext="true" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 
 
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
 
</configuration>

Application Configuration sample

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <connectionStrings>
    <add name="MT_ConnectionString"
      connectionString="Data Source=NOKIA;Initial Catalog=ShopMT;Persist Security Info=True;User ID=sa;Password=sa21"
      providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IMTService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:50:00" sendTimeout="00:50:00"
          bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="2000000000" maxReceivedMessageSize="2000000000"
          messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
          allowCookies="false">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <reliableSession ordered="true" inactivityTimeout="00:50:00"
            enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="Windows" negotiateServiceCredential="false"
              algorithmSuite="Default" establishSecurityContext="true" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost/MT/MTService.svc/MTService"
          binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMTService"
          contract="MTService.IMTService" name="WSHttpBinding_IMTService"
                behaviorConfiguration="EndPointBehavior">
        <identity>
          <dns value="apps.mediasoftbd.com" />
        </identity>
      </endpoint>
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="EndPointBehavior">
          <dataContractSerializer maxItemsInObjectGraph="1909600"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

Exception from HRESULT: 0x80070057 (E_INVALIDARG)

Monday, February 11, 2013 Category : 0


Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

 
[FileLoadException: Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +416
   System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +166
   System.Reflection.Assembly.Load(String assemblyString) +35
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +190

[ConfigurationErrorsException: Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11224200
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +388
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +232
   System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +48
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +210
   System.Web.Compilation.WebDirectoryBatchCompiler..ctor(VirtualDirectory vdir) +191
   System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors) +54
   System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +295
   System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +476
   System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +116
   System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +175
   System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +52
   System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +50
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +425
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +263

 

Solution:
This method worked for me,

-Stop IIS server or VS

-go to:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

-and delete all folders in this directory

-launch IIS or VS

What is Reflection in .net

Category : 0

The main value of Reflection is that it can be used to inspect assemblies, types, and members. It's a very powerful tool for determining the contents of an unknown assembly or object and can be used in a wide variety of cases.
Opponents of Reflection will cite that it is slow, which is true when compared to static code execution--however Reflection is used throughout the .NET framework, and provided that it's not abused it can be a very powerful tool in the toolkit.
Some useful applications:
  • Determing dependancies of an assembly
  • Location types which conform to an interface, derive from a base / abstract class, and searching for members by attributes
  • (Smelly) testing - If you depend on a class which is untestable (ie it doesn't allow you to easily build a fake) you can use Reflection to inject fake values within the class--it's not pretty, and not recommended, but it can be a handy tool in a bind.
  • Debugging - dumping out a list of the loaded assemblies, their references, current methods, etc...

    http://stackoverflow.com/questions/1458256/why-use-of-reflection-in-net-c-sharp-code-are-recommended


The only place I've used the Reflection stuff in C# was in factory patterns, where I'm creating objects (in my case, network listeners) based on configuration file information. The configuration file supplied the location of the assemblies, the name of the types within them, and any additional arguments needed. The factory picked this stuff up and created the listeners based on that.

http://stackoverflow.com/questions/429962/when-do-you-use-reflection-patterns-anti-patterns


What is .NET Reflection?

.NET Framework's Reflection API allows you to fetch type (assembly) information at runtime programmatically. We can also achieve late binding by using .NET Reflection. At runtime, the Reflection mechanism uses the PE file to read information about the assembly. Reflection enables you to use code that is not available at compile time. .NET Reflection allows an application to collect information about itself and also to manipulate on itself. It can be used effectively to find all types in an assembly and/or dynamically invoke methods in an assembly. This includes information about the type, properties, methods, and events of an object. With Reflection, we can dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and invoke its methods or access its fields and properties. We can also access attribute information using Reflection.
Using Reflection, you can get any kind of information which you can see in a class viewer; for example, information on the methods, properties, fields, and events of an object.

http://www.codeproject.com/Articles/55710/Reflection-in-NET

Crystal report error (Load report failed) in asp.net

Saturday, February 9, 2013 Category : , 0

There are various reason for this error. in the following list all may cause this problem


1.

public static ReportDocument rep = new ReportDocument();
   protected void Page_UnLoad(object sender, EventArgs e)
   {
       this.CrystalReportViewer1.Dispose();
       this.CrystalReportViewer1 = null;
       rep.Close();
       rep.Dispose();
       GC.Collect();
   }
 
 
2. crystal report assemblies installed on your machine do not reflect the assemblies you have on your web.config

3. crystal version installed on the server is different with the one you want to invoke from your site

4. application pool where your reports run is not set to LOCAL SERVICE

5. read and write permission is not enabled on your root folder

6. crystalreportviewer folder is not copied to your operating folder. 
 
 
7. lack of permission in following  directory

The fix: When Crystal Reports opens a file, it uses the Windows temporary folder (typically C:\Windows\Temp\) as a scratch-pad. You need to give Crystal Reports explicit permission to read and write to this folder.

How-to: Under XP, ASP.NET runs CR under ASPNET; with most of the Windows Server flavors, CR runs as NETWORK SERVICE. Make sure that this identity has permission to read and write to the Windows temporary folder.
1. Ensure the RPT file name is correct. Filename must be a fully qualified valid path name (such as C:\MyApp\MyReport.rpt).
2. The ASPNET account has permissions to open the file.  Make sure the folder containing the file and the file itself has the same permissions as your application folder.


But still i don't found any solution
next i tried to discover my iis different settings. and i found an interesting option.
* select your application pool for your apllication or website
* Click on Recycling (Right side panel)
* Reduce the value of Regular time interval 1740 to 20 min or set your desire value you want
* this  will release any resource hold by iis.

And This has help me to overcome this error

C# Time To Word (Bangla)

Sunday, January 27, 2013 Category : 0

class TimeToWord
    {
        public string ConvertEnglish()
        {
            return "";
        }

        public string ConvertBangla(DateTime dt)
        {
            int hour = dt.Hour;
            int minute = dt.Minute;

            string BanglaValue = "";

            if (hour < 12)
            {
                BanglaValue += @"সকাল";
            }
            else if (hour >= 12)
            {
                BanglaValue += @"দুপুর";
            }

            #region hour in bangla
            if (hour == 1) { BanglaValue += @" একটা"; }
            else if (hour == 2) { BanglaValue += @" দুইটা"; }
            else if (hour == 3) { BanglaValue += @" তিনটা"; }
            else if (hour == 4) { BanglaValue += @" চারটা"; }
            else if (hour == 5) { BanglaValue += @" পাচঁটা"; }
            else if (hour == 6) { BanglaValue += @" ছয়টা"; }
            else if (hour == 7) { BanglaValue += @" সাতটা"; }
            else if (hour == 8) { BanglaValue += @" আটটা"; }
            else if (hour == 9) { BanglaValue += @" নয়টা"; }
            else if (hour == 10) { BanglaValue += @" দশটা"; }
            else if (hour == 11) { BanglaValue += @" এগারোটা"; }
            else if (hour == 12) { BanglaValue += @" বারোটা"; }
            else if (hour == 13) { BanglaValue += @" একটা"; }
            else if (hour == 14) { BanglaValue += @" দুইটা"; }
            else if (hour == 15) { BanglaValue += @" তিনটা"; }
            else if (hour == 16) { BanglaValue += @" চারটা"; }
            else if (hour == 17) { BanglaValue += @" পাচঁটা"; }
            else if (hour == 18) { BanglaValue += @" ছয়টা"; }
            else if (hour == 19) { BanglaValue += @" সাতটা"; }
            else if (hour == 20) { BanglaValue += @" আটটা"; }
            else if (hour == 21) { BanglaValue += @" নয়টা"; }
            else if (hour == 22) { BanglaValue += @" দশটা"; }
            else if (hour == 23) { BanglaValue += @" এগারোটা"; }
            else if (hour == 24) { BanglaValue += @" বারোটা"; }
            #endregion


            #region minute in bangla
            if (minute == 1) { BanglaValue += @" এক"; }
            else if (minute == 2) { BanglaValue += @" দুই"; }
            else if (minute == 3) { BanglaValue += @" তিন"; }
            else if (minute == 4) { BanglaValue += @" চার"; }
            else if (minute == 5) { BanglaValue += @" পাচঁ"; }
            else if (minute == 6) { BanglaValue += @" ছয়"; }
            else if (minute == 7) { BanglaValue += @" সাত"; }
            else if (minute == 8) { BanglaValue += @" আট"; }
            else if (minute == 9) { BanglaValue += @" নয়"; }
            else if (minute == 10) { BanglaValue += @" দশ"; }
            else if (minute == 11) { BanglaValue += @" এগারো"; }
            else if (minute == 12) { BanglaValue += @" বারো"; }

                /*
                 * তেরো চৈাদ্দো্ পনেরো ষোলো সতেরো আঠারো উনিশ বিষ একুশ বাইষ তেইশ চব্বিশ পঁচিশ ছ্ছাব্বিশ সাতাইশ আঠাইশ
উনত্রিশ ত্রিশ একত্রিশ বত্রিশ তেত্রিশ চৈাত্রিশ পয়ত্রিশ ছত্রিশ সাইত্রিশ আটত্রিশ উনচল্লিশ চল্লিশ একল্লিশ বিয়াল্লিশ তেতাল্লিশ চুয়াল্লিশ পঁয়তাল্লিশ ছেঁচোল্লিশ সাতচল্লিশ
                 * আটচল্লিশ উনপন্চাশ পঞ্চাশ একান্নো বাহান্নো তিপ্পান্নো চুয়ান্নো পঞ্চান্নো ছাপ্পানো সাতান্নো আটান্নো উনষাট
                 * */

            else if (minute == 13) { BanglaValue += @" তেরো"; }
            else if (minute == 14) { BanglaValue += @" চৈাদ্দো্"; }
            else if (minute == 15) { BanglaValue += @" পনেরো"; }
            else if (minute == 16) { BanglaValue += @" ষোলো"; }
            else if (minute == 17) { BanglaValue += @" সতেরো"; }
            else if (minute == 18) { BanglaValue += @" আঠারো"; }
            else if (minute == 19) { BanglaValue += @" উনিশ"; }
            else if (minute == 20) { BanglaValue += @" বিষ"; }
            else if (minute == 21) { BanglaValue += @" একুশ"; }
            else if (minute == 22) { BanglaValue += @" বাইশ"; }
            else if (minute == 23) { BanglaValue += @" তেইশ"; }
            else if (minute == 24) { BanglaValue += @" চব্বিশ"; }
            else if (minute == 25) { BanglaValue += @" পঁচিশ"; }
            else if (minute == 26) { BanglaValue += @" ছ্ছাব্বিশ"; }
            else if (minute == 27) { BanglaValue += @" সাতাইশ"; }
            else if (minute == 28) { BanglaValue += @" আঠাইশ"; }
            else if (minute == 29) { BanglaValue += @" উনত্রিশ"; }
            else if (minute == 30) { BanglaValue += @" ত্রিশ"; }
            else if (minute == 31) { BanglaValue += @" একত্রিশ"; }
            else if (minute == 32) { BanglaValue += @" বত্রিশ"; }
            else if (minute == 33) { BanglaValue += @" তেত্রিশ"; }
            else if (minute == 34) { BanglaValue += @" চৈাত্রিশ"; }
            else if (minute == 35) { BanglaValue += @" পয়ত্রিশ"; }

            else if (minute == 36) { BanglaValue += @" ছত্রিশ"; }
            else if (minute == 37) { BanglaValue += @" সাইত্রিশ"; }
            else if (minute == 38) { BanglaValue += @" আটত্রিশ"; }
            else if (minute == 39) { BanglaValue += @" উনচল্লিশ"; }
            else if (hour == 40) { BanglaValue += @" চল্লিশ"; }
            else if (minute == 41) { BanglaValue += @" একচল্লিশ"; }
            else if (minute == 42) { BanglaValue += @" বিয়াল্লিশ"; }
            else if (minute == 43) { BanglaValue += @" তেতাল্লিশ"; }
            else if (minute == 44) { BanglaValue += @" চুয়াল্লিশ"; }
            else if (minute == 45) { BanglaValue += @" পঁয়তাল্লিশ"; }
            else if (minute == 46) { BanglaValue += @" ছেঁচোল্লিশ"; }
            else if (minute == 47) { BanglaValue += @" সাতচল্লিশ"; }
            else if (minute == 48) { BanglaValue += @" আটচল্লিশ"; }

            else if (minute == 49) { BanglaValue += @" উনপন্চাশ"; }
            else if (minute == 50) { BanglaValue += @" পঞ্চাশ"; }
            else if (minute == 51) { BanglaValue += @" একান্নো"; }
            else if (minute == 52) { BanglaValue += @" বাহান্নো"; }
            else if (minute == 53) { BanglaValue += @" তিপ্পান্নো"; }
            else if (minute == 54) { BanglaValue += @" চুয়ান্নো"; }
            else if (minute == 55) { BanglaValue += @" পঞ্চান্নো"; }
            else if (minute == 56) { BanglaValue += @" ছাপ্পানো"; }
            else if (minute == 57) { BanglaValue += @" সাতান্নো"; }
            else if (minute == 58) { BanglaValue += @" আটান্নো"; }
            else if (minute == 59) { BanglaValue += @" উনষাট"; }

            #endregion
            return BanglaValue;
        }
    }

C# date to word (Bangla)

Category : 0

class DateToWord
    {
        public string ConvertEnglish()
        {
            return "";
        }

        public string ConvertBangla(DateTime dt)
        {
            int day = dt.Day;
            int month = dt.Month;
            int year = dt.Year;

            string BanglaValue = "";

            //if (day < 12)
            //{
            //    BanglaValue += @"সকাল";
            //}
            //else if (day >= 12)
            //{
            //    BanglaValue += @"দুপুর";
            //}

            #region day in bangla
            if (day == 1) { BanglaValue += @"এক"; }
            else if (day == 2) { BanglaValue += @"দুই"; }
            else if (day == 3) { BanglaValue += @"তিন"; }
            else if (day == 4) { BanglaValue += @"চার"; }
            else if (day == 5) { BanglaValue += @"পাচঁ"; }
            else if (day == 6) { BanglaValue += @"ছয়"; }
            else if (day == 7) { BanglaValue += @"সাত"; }
            else if (day == 8) { BanglaValue += @"আট"; }
            else if (day == 9) { BanglaValue += @"নয়"; }
            else if (day == 10) { BanglaValue += @"দশ"; }
            else if (day == 11) { BanglaValue += @"এগারো"; }
            else if (day == 12) { BanglaValue += @"বারো"; }

            else if (day == 13) { BanglaValue += @" তেরো"; }
            else if (day == 14) { BanglaValue += @" চৈাদ্দো্"; }
            else if (day == 15) { BanglaValue += @" পনেরো"; }
            else if (day == 16) { BanglaValue += @" ষোলো"; }
            else if (day == 17) { BanglaValue += @" সতেরো"; }
            else if (day == 18) { BanglaValue += @" আঠারো"; }
            else if (day == 19) { BanglaValue += @" উনিশ"; }
            else if (day == 20) { BanglaValue += @" বিষ"; }
            else if (day == 21) { BanglaValue += @" একুশ"; }
            else if (day == 22) { BanglaValue += @" বাইশ"; }
            else if (day == 23) { BanglaValue += @" তেইশ"; }
            else if (day == 24) { BanglaValue += @" চব্বিশ"; }
            else if (day == 25) { BanglaValue += @" পঁচিশ"; }
            else if (day == 26) { BanglaValue += @" ছ্ছাব্বিশ"; }
            else if (day == 27) { BanglaValue += @" সাতাইশ"; }
            else if (day == 28) { BanglaValue += @" আঠাইশ"; }
            else if (day == 29) { BanglaValue += @" উনত্রিশ"; }
            else if (day == 30) { BanglaValue += @" ত্রিশ"; }
            else if (day == 31) { BanglaValue += @" একত্রিশ"; }
            #endregion

            /*
             * জানুয়ারি ফেব্রুয়ারি মার্চ এপ্রিল মে জুন জুলাই আগস্ট সেপেট্মবর অক্টো্বর নভেম্বর ডিসেম্বর
             * */
            #region month in bangla
            if (month == 1) { BanglaValue += @" জানুয়ারি"; }
            else if (month == 2) { BanglaValue += @" ফেব্রুয়ারি"; }
            else if (month == 3) { BanglaValue += @" মার্চ"; }
            else if (month == 4) { BanglaValue += @" এপ্রিল"; }
            else if (month == 5) { BanglaValue += @" মে"; }
            else if (month == 6) { BanglaValue += @" জুন"; }
            else if (month == 7) { BanglaValue += @" জুলাই"; }
            else if (month == 8) { BanglaValue += @" আগস্ট"; }
            else if (month == 9) { BanglaValue += @" সেপেট্মবর"; }
            else if (month == 10) { BanglaValue += @" অক্টো্বর"; }
            else if (month == 11) { BanglaValue += @" নভেম্বর"; }
            else if (month == 12) { BanglaValue += @" ডিসেম্বর"; }
            #endregion

            /*
             * ২০১০ ২০১১ ২০১২ ২০১৩ ২০১৪ ২০১৫ ২০১৬ ২০১৭ ২০১৮ ২০১৯ ২০২০
             * */
            #region year in bangla
            if (year == 2010) { BanglaValue += @" ২০১০"; }
            else if (year == 2011) { BanglaValue += @" ২০১১"; }
            else if (year == 2012) { BanglaValue += @" ২০১২"; }
            else if (year == 2013) { BanglaValue += @" ২০১৩"; }
            else if (year == 2014) { BanglaValue += @" ২০১৪"; }
            else if (year == 2015) { BanglaValue += @" ২০১৫"; }
            else if (year == 2016) { BanglaValue += @" ২০১৬"; }
            else if (year == 2017) { BanglaValue += @" ২০১৭"; }
            else if (year == 2018) { BanglaValue += @" ২০১৮"; }
            else if (year == 2019) { BanglaValue += @" ২০১৯"; }
            else if (year == 2020) { BanglaValue += @" ২০২০"; }
            else if (year == 2021) { BanglaValue += @" ২০২১"; }
            #endregion

            return BanglaValue;
        }
    }

ASP.NET Image Uploader Class example

Thursday, January 17, 2013 Category : 0

  <p align="center">
                        <asp:Image ID="Image1" runat="server" Height="105px"
                            ImageUrl="~/Images/default.gif" Width="135px" /><br />
                        <asp:Label ID="lblUploadStatus" runat="server" Text=""></asp:Label>
                        <asp:FileUpload ID="FileUpload1" runat="server" /><br />
                        <asp:LinkButton ID="LinkButton1"
                            runat="server" onclick="LinkButton1_Click">Upload</asp:LinkButton>
                            <br />
                          
                        <asp:Button ID="btnChangeImage" runat="server" Text="Change"
                            onclick="btnChangeImage_Click" />
                    </p>

public class Uploader : System.Web.UI.Page
    {
        public string UploadItemImage(FileUpload fileUpload)
        {
            string filePath = "";
            if (fileUpload.HasFile)
            {
                if (CheckFileType(fileUpload))
                {
                    string postedLogo = fileUpload.PostedFile.FileName.ToString();
                    string fileName = postedLogo.Split(new char[] { '\\' }).Last();
                    MembershipUser mu = Membership.GetUser();
                    string fileExtension = fileUpload.PostedFile.FileName.Split(new char[] { '.' }).Last().ToLower();
                    filePath = "~/ItemImages/" + fileUpload.FileName.Replace(fileName, mu.UserName + "." + fileExtension);


                    string filename = mu.UserName + "." + fileExtension;

                    try
                    {
                        System.Drawing.Image UploadedImage = System.Drawing.Image.FromStream(fileUpload.PostedFile.InputStream);


                        if (System.IO.File.Exists(Server.MapPath(filePath)))
                        {
                            System.IO.File.Delete(Server.MapPath(filePath));
                        }

                        ResizeImage(filename, fileUpload);

                        Session["imgPathItem"] = filePath;
                        return filePath;
                    }
                    catch (Exception ex)
                    {
                        Session["ex"] = ex.Message;
                    }
                }
                else
                {

                    return "";

                }
            }
            else
            {
                return "";

            }
            return "";
        }


        private void ResizeImage(string filename,FileUpload fileUpload)
        {

            if (!Directory.Exists(Server.MapPath(@"~/ItemImages")))
                {
                    Directory.CreateDirectory(Server.MapPath(@"~/ItemImages"));
                }
                string directory = Server.MapPath(@"~/ItemImages/") + filename;
                Bitmap originalBMP = new Bitmap(fileUpload.FileContent);
                int origWidth = originalBMP.Width;
                int origHeight = originalBMP.Height;
                int sngRatio = ((int)(origWidth / origHeight) == 0) ? 1 : (origWidth / origHeight);
                int newWidth = 150;
                int newHeight = newWidth / sngRatio;
                Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
                Graphics oGraphics = Graphics.FromImage(newBMP);

                oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);

                newBMP.Save(directory, ImageFormat.Jpeg);
              
                originalBMP.Dispose();
                newBMP.Dispose();
                oGraphics.Dispose();
           
          
        }

        public bool SaveFinalFile(string fileLoc, string newFileName)
        {
            try
            {
                if (File.Exists(Server.MapPath(fileLoc)))
                {
                    string newFileLocation = Server.MapPath(@"~/ItemImages/") + newFileName + "." + Session["imageExtensition"].ToString();
                    File.Copy(Server.MapPath(fileLoc), newFileLocation,true);
                    Session["imgPathItem"] = @"~/ItemImages/" + newFileName + "." + Session["imageExtensition"].ToString();
                    return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return false;
        }

        private bool CheckFileType(FileUpload fileUpload)
        {
            string[] fileTypeList = { "jpeg", "jpg", "gif", "bmp", "png" };
            string fileExtension = fileUpload.PostedFile.FileName.Split(new char[] { '.' }).Last().ToLower();
            bool flag = false;
            for (int i = 0; i < fileTypeList.Count(); i++)
            {
                if (fileExtension == fileTypeList[i])
                {
                    flag = true;
                    Session["imageExtensition"] = fileExtension;
                    break;
                }
            }
            if (flag)
            {
                return true;
            }
            return false;
        }

    }

Powered by Blogger.