{"id":132,"date":"2010-05-13T20:05:41","date_gmt":"2010-05-13T14:35:41","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=132"},"modified":"2010-05-13T20:05:41","modified_gmt":"2010-05-13T14:35:41","slug":"upload-files-in-asp-net-at-production-server","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/upload-files-in-asp-net-at-production-server\/","title":{"rendered":"Upload Files in ASP.NET at Production server"},"content":{"rendered":"<p>In this article, i am going to demonstrate that how to upload the file in ASP.NET production server.<\/p>\n<p>Most of the case, a developer created a code to upload the file and test it on his local machine. program runs smoothly, but as he\u00a0forward\u00a0the same code on production. He\u00a0stuck\u00a0in the <strong>file permission error<\/strong> as on the local he has the full permission whereas on development its not the case.<\/p>\n<p>So i decided to write this tutorial for the\u00a0beginners which will demonstrate lots of ASP.NET features.<\/p>\n<p>First we need to create a folder in Server and share it with ASP.NET web server as described.<\/p>\n<p>Right click on folder, select Web sharing tab and select the radio button &#8220;Share this folder&#8221;. One \u00a0window appear, give it alias name which will be used in\u00a0coding.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/WebShare-Folder.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-133\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/WebShare-Folder.png?resize=471%2C510&#038;ssl=1\" alt=\"\" width=\"471\" height=\"510\" \/><\/a><\/p>\n<p>After this, open Run box and type &#8220;<strong>inetmgr<\/strong>&#8220;. you will see that your web shared folder appears in the IIS.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/IIS.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-134\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/IIS.png?resize=274%2C476&#038;ssl=1\" alt=\"\" width=\"274\" height=\"476\" \/><\/a><\/p>\n<p>Right click on folders property. one window will opened.<\/p>\n<p>Select &#8220;Directory Security&#8221; tab then click on &#8220;Edit&#8221; button and then check &#8220;Anonymous access&#8221;. And because of this setting any body can access or download that file.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/anonomouse-Access.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-147\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/anonomouse-Access.png?resize=643%2C566&#038;ssl=1\" alt=\"\" width=\"643\" height=\"566\" \/><\/a><\/p>\n<p>Now we are ready, to create a sample application which will demonstrate that how to upload the file and use it.<\/p>\n<p>Create ASP.NET project in Visual Studio. Create a webpage with fileupload, hyperlink and button control.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;\n&lt;asp:FileUpload ID=&quot;uploadFile&quot; runat=&quot;server&quot; \/&gt;&lt;br \/&gt;\n&lt;asp:HyperLink ID=&quot;hypLink&quot; runat=&quot;server&quot; Visible=&quot;false&quot; Target=&quot;_blank&quot;&gt;&lt;\/asp:HyperLink&gt;&lt;br \/&gt;\n&lt;asp:Button ID=&quot;btnUpload&quot; Text=&quot;Upload&quot; runat=&quot;server&quot; OnClick=&quot;btnUpload_Click&quot; \/&gt;\n&lt;\/form&gt;\n\n<\/pre>\n<p>In <strong>web.config<\/strong> add two keys. \u00a0One for actual folder location in which we are going to upload the files and other its alias name. we can also hard code that, but its good practice to make it configurable at any time because in near future we may want to change the location.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n\n&lt;appSettings&gt;\n\n&lt;add key=&quot;DemoAttachment&quot; value=&quot;D:ShareDemoShare&quot;&gt;&lt;\/add&gt;\n\n&lt;add key=&quot;DemoAttachmentVirtualPath&quot; value=&quot;http:\/\/localhost\/DemoShare\/&quot;&gt;&lt;\/add&gt;\n\n&lt;\/appSettings&gt;\n\n<\/pre>\n<p>In\u00a0DemoAttachmentVirtualPath key, value should like<strong> &#8220;http:\/\/machinename\/&#8221; + Alias folder name.<\/strong><\/p>\n<p>On click event of button, write below code:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nstring strPath = ConfigurationManager.AppSettings&#x5B;&quot;DemoAttachment&quot;];\nuploadFile.SaveAs(strPath + System.IO.Path.GetFileName(uploadFile.FileName));\nhypLink.Visible = true;\nstring VirtualPath = ConfigurationManager.AppSettings&#x5B;&quot;DemoAttachmentVirtualPath&quot;];\nhypLink.Text = System.IO.Path.GetFileName(uploadFile.FileName);\nhypLink.NavigateUrl = VirtualPath + uploadFile.FileName;\nstring strPath = ConfigurationManager.AppSettings&#x5B;&quot;DemoAttachment&quot;];\n\nuploadFile.SaveAs(strPath + System.IO.Path.GetFileName(uploadFile.FileName));\nhypLink.Visible = true;\nstring VirtualPath = ConfigurationManager.AppSettings&#x5B;&quot;DemoAttachmentVirtualPath&quot;];\n\nhypLink.Text = System.IO.Path.GetFileName(uploadFile.FileName);\n\nhypLink.NavigateUrl = VirtualPath + uploadFile.FileName;\n\n<\/pre>\n<p>The output will look like:<\/p>\n<h1 style=\"text-align: center;\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/output.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-137\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/output.png?resize=452%2C446&#038;ssl=1\" alt=\"\" width=\"452\" height=\"446\" \/><\/a><a href=\"https:\/\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/FileUploadDemo.zip\">Download Source code<\/a><\/h1>\n<p>For the file size limitation, please visit this article : <a href=\"https:\/\/jitendrazaa.com\/blog\/?p=125\">https:\/\/jitendrazaa.com\/blog\/?p=125<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, i am going to demonstrate that how to upload the file in ASP.NET production server. Most of the case, a developer created a code to upload the file and test it on his local machine. program runs smoothly, but as he\u00a0forward\u00a0the same code on production. He\u00a0stuck\u00a0in the file permission error as on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":330,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[21],"tags":[43,51,100,117],"class_list":["post-132","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net","tag-asp-net","tag-c","tag-fileupload","tag-iis"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":125,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/cannot-access-a-closed-file-fileupload-in-asp-net\/","url_meta":{"origin":132,"position":0},"title":"cannot access a closed file &#8211; FileUpload in ASP.NET","author":"Jitendra","date":"May 13, 2010","format":false,"excerpt":"This was very\u00a0interesting\u00a0error, i got during development of file upload control in ASP.NET. On my local system, every thing was just fine. but when i deployed my application on development server, my control was able to upload only small size files. whenever i tried to upload large size file i\u2026","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":71,"url":"https:\/\/www.jitendrazaa.com\/blog\/webtech\/web\/style-file-upload-control-in-asp-html\/","url_meta":{"origin":132,"position":1},"title":"Style File upload control in ASP \/ HTML","author":"Jitendra","date":"May 10, 2010","format":false,"excerpt":"As most of us know that we cannot style the file upload control to much level, still we can give it a stunning effect with the help of CSS. There is nothing in code to explain. I took three upload control and one button to give effect. Lets say upload\u2026","rel":"","context":"In &quot;HTML&quot;","block_context":{"text":"HTML","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/webtech\/web\/"},"img":{"alt_text":"Output in Chrom","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/Output-in-Chrom-300x82.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":12,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/use-fxcop-with-asp-net\/","url_meta":{"origin":132,"position":2},"title":"Use FXcop with ASP.NET","author":"Jitendra","date":"May 4, 2010","format":false,"excerpt":"FxCop, an abbreviation \"Framework Police,\" is a rules-based engine that checks managed code assemblies for Microsoft's .NET Framework design guidelines and custom guidelines. FxCop is a rule based engine which helps the development team to follow best practices of the .NET platform and development standards (based on every company standards).\u2026","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":15,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/app_offline-htm-in-asp-net\/","url_meta":{"origin":132,"position":3},"title":"App_Offline.htm in ASP.NET","author":"Jitendra","date":"May 5, 2010","format":false,"excerpt":"If you place a file with the name App_Offline.htm in the root of a web application directory, ASP.NET 2.0 will shut-down the application, unload the application domain from the server, and stop processing any new incoming requests for that application. ASP.NET will also then respond to all requests for dynamic\u2026","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":827,"url":"https:\/\/www.jitendrazaa.com\/blog\/webtech\/add-css-programatically-in-asp-net\/","url_meta":{"origin":132,"position":4},"title":"Add CSS Programatically in ASP.NET","author":"Jitendra","date":"September 3, 2010","format":false,"excerpt":"Tutorial on adding the CSS file dynamically in ASP.NET and C# \/ VB.Net","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2299,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/tutorial-read-and-export-excel-file-in-asp-net-using-c\/","url_meta":{"origin":132,"position":5},"title":"Tutorial &#8211; Read and export excel file in ASP.Net  using C#","author":"Jitendra","date":"July 29, 2011","format":false,"excerpt":"Tutorial - Read and export excel file in ASP.Net using C#","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"Read And Export Excel in ASP.Net","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/07\/Read-And-Export-Excel-in-ASP.Net_.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=132"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/132\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}