tag:blogger.com,1999:blog-87728319268486957942024-03-13T03:03:59.414-07:00Programming HurdlesFree learn programming, How to Program, solve problem during programming, Programming herding, get help during programming.azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.comBlogger19125tag:blogger.com,1999:blog-8772831926848695794.post-51159864692773842772023-02-12T01:34:00.002-08:002023-02-12T02:26:28.515-08:00API Gateway and their use<p>API Gateway</p><p>API gateways are used to manage, secure, and scale APIs. Some of the key uses of API gateways include:</p><p></p><ol style="text-align: left;"><li>Traffic Management: API gateways can be used to control the flow of incoming API requests, such as rate limiting and caching. This helps to ensure that APIs are available and responsive even under heavy traffic conditions.</li><li>Security: API gateways provide security features such as authentication and authorization, which helps to protect APIs and the data they expose. They also provide encryption and secure communication between the API gateway and the backend systems.</li><li>Transformation: API gateways can transform incoming API requests to match the format required by the backend systems, and vice versa. This helps to ensure that APIs can be easily consumed by various clients, regardless of the format of the data they expect.</li><li>Monitoring and Logging: API gateways provide real-time visibility into the health and performance of APIs. This can help organizations to detect and troubleshoot issues quickly and effectively.</li><li>Developer Portal: API gateways often include a developer portal that provides documentation, SDKs, and other tools to help developers get started with using the APIs.</li><li>Microservice Management: In microservice architectures, API gateways act as the entry point to the system, routing requests to the appropriate microservice and aggregating the responses from multiple microservices into a single API response.</li></ol><p></p><p>Overall, API gateways provide a centralized and unified way to manage and control APIs, making it easier for organizations to develop, deploy, and maintain their APIs in a scalable and secure manner. </p><p><br /></p><p>The most common API Gateway:</p><p>There are several common API gateways used by organizations to manage their APIs. Some of the most popular ones include:</p><p></p><ul style="text-align: left;"><li>Amazon API Gateway: a fully managed service from Amazon Web Services (AWS) for creating, deploying, and managing APIs.</li><li>Kong: an open-source API gateway written in Lua that can be used to manage and secure microservices.</li><li>Tyk: an open-source, high-performance API gateway written in Go.</li><li>Express Gateway: an open-source API gateway written in Node.js that is designed to be a simple and scalable solution for small to medium-sized organizations.</li><li>Google Cloud Endpoints: a fully managed service from Google Cloud that makes it easy to create, deploy, and manage APIs.</li><li>Azure API Management: a fully managed service from Microsoft Azure that provides a complete solution for creating, publishing, and managing APIs.</li><li>NGINX: a high-performance HTTP server and reverse proxy that can also be used as an API gateway.</li></ul><p></p><p>These are some of the most popular API gateways, but there are many others available, each with its own unique features and benefits.</p><p><br /></p>azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-1441181388366123792020-11-07T06:50:00.007-08:002020-11-09T01:25:51.363-08:00<p><span style="font-size: large;"> <b>How to send Large Size Object in ASP.Net Web API</b></span></p><p>There are multiples issue when you send the large object or file to the web API that hosted within IIS context, because there are some default limitation on the service by the Framework.</p><p>you might be faced an out of memory issues when allowing the Large Object especially large bytes</p><p>You can configure the large size by through IIS configuration or by ASP.Net </p><p><b>1. ASP.NET</b></p><p>ASP.NET runtime has its own file size limit which is located under the httpRuntime element of the web.config.</p><p>The default size is set to 4096 KB (4 MB). it’s set in KB instead of bytes as example below:</p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAm13dyN1tMu_XCowJHHMI2_Ltmw7pLCOiU4JxnJ6_rhz_7KmdHS09J-B4PG-OzPZeVxjMZU6gD8ffac49-mCLLdy64l2gSyrsl2UClAGvVkf9ChmYSyWikVpvbUsvlvAj7FpZeE3A8Vvd/s375/image_2020_11_07T14_29_30_501Z.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="73" data-original-width="375" height="100" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAm13dyN1tMu_XCowJHHMI2_Ltmw7pLCOiU4JxnJ6_rhz_7KmdHS09J-B4PG-OzPZeVxjMZU6gD8ffac49-mCLLdy64l2gSyrsl2UClAGvVkf9ChmYSyWikVpvbUsvlvAj7FpZeE3A8Vvd/w518-h100/image_2020_11_07T14_29_30_501Z.png" width="518" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><p><b>2. IIS</b></p><p>The default file is 30000000 bytes more then 28 MB, if you tried to send file with more then 28 mb the response will be 404 error, So you need to explicitly change the web.config file to allow the large size. you can use <b>maxRequestLength </b>and or <b>maxAllowedContentLength </b>depend on the IIS version you are using.</p><p><b>maxRequestLength </b>option to set the the maximum request size for ASP.NET, whereas <b>maxAllowedContentLength </b>use to set the maximum length of content in a request supported by IIS</p><p>See the example Below:</p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGjLVWoGchtPgjYxcXXnmPoZXno4g3a77XSnRWWlD_RfcKBhDjlLpRSmTTks6JF_iQvz1Eruo9K6Aai4VFSvEdK-5CTTP-I5l-uVZvhUv-CBoqkfYr0B1kcT3Zh8mPuWNGepgrq3DKDdsa/s676/image_2020_11_07T13_22_05_452Z.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="242" data-original-width="676" height="201" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGjLVWoGchtPgjYxcXXnmPoZXno4g3a77XSnRWWlD_RfcKBhDjlLpRSmTTks6JF_iQvz1Eruo9K6Aai4VFSvEdK-5CTTP-I5l-uVZvhUv-CBoqkfYr0B1kcT3Zh8mPuWNGepgrq3DKDdsa/w558-h201/image_2020_11_07T13_22_05_452Z.png" width="558" /></a></div><div><div><br /></div><div>By default, Web API buffer the request input stream in to the memory and it can cause out of memory error since we have increased the limit of 2 GB with just couple of simultaneous uploads. there is a way to to change this mode for the Web API so that its streamed mode deal with uploaded file and not buffer the entire request stream in memory.</div><div>We just need to replace the default IHostBufferPolicySelector with our custom implementation as below:</div><div><span style="color: #2b00fe;">public interface IHostBufferPolicySelector</span></div><div><span style="color: #2b00fe;">{</span></div><div><span style="color: #2b00fe;"> bool UseBufferedInputStream(object hostContext);</span></div><div><span style="color: #2b00fe;"> bool UseBufferedOutputStream(HttpResponseMessage response);</span></div><div><span style="color: #2b00fe;">}</span></div><div><span style="color: #2b00fe;"><br /></span></div><div> per request service will makes a decision that request should be buffered or not</div><div><br /></div><div><span style="color: #2b00fe;">public class NoBufferPolicySelector : WebHostBufferPolicySelector</span></div><div><span style="color: #2b00fe;">{</span></div><div><span style="color: #2b00fe;"> public override bool UseBufferedInputStream(object hostContext)</span></div><div><span style="color: #2b00fe;"> {</span></div><div><span style="color: #2b00fe;"> var context = hostContext as HttpContextBase;</span></div><div><span style="color: #2b00fe;"> </span></div><div><span style="color: #2b00fe;"> if (context != null)</span></div><div><span style="color: #2b00fe;"> {</span></div><div><span style="color: #2b00fe;"> if (string.Equals(context.Request.RequestContext.RouteData.Values["controller"].ToString(), "uploading", StringComparison.InvariantCultureIgnoreCase))</span></div><div><span style="color: #2b00fe;"> return false;</span></div><div><span style="color: #2b00fe;"> }</span></div><div><span style="color: #2b00fe;"> </span></div><div><span style="color: #2b00fe;"> return true;</span></div><div><span style="color: #2b00fe;"> }</span></div><div> </div><div> <span style="color: #2b00fe;"> public override bool UseBufferedOutputStream(HttpResponseMessage response)</span></div><div><span style="color: #2b00fe;"> {</span></div><div><span style="color: #2b00fe;"> return base.UseBufferedOutputStream(response);</span></div><div><span style="color: #2b00fe;"> }</span></div><div><span style="color: #2b00fe;">}</span></div><div><span style="color: #2b00fe;"><br /></span></div><div>Now we need to register the service in <b>GlobalConfiguration </b>as this service should always be global.</div><div><br /></div><div><span style="color: #2b00fe;">GlobalConfiguration.Configuration.Services.Replace(typeof(IHostBufferPolicySelector), new NoBufferPolicySelector());</span></div><div><br /></div><div>In .Net Framework V 4 by default <b>HttpClient </b>will buffer the body. so if you want to control the request/ response whether they are buffered or streamed to overcome the out of memory issue, you should use the <b>HttpWebRequest </b>directly as we have more control on <b>HttpWebRequest </b>over <b>HttpClient </b>even it lies under the <b>HttpClient </b>but these properties are not exposed to the consumer by <b>HttpClient</b></div><div><b><br /></b></div><div><span style="color: #2b00fe;">HttpWebRequest.AllowReadStreamBuffering </span></div><div><span style="color: #2b00fe;">HttpWebRequest.AllowWriteStreamBuffering</span></div></div><div><span style="color: #2b00fe;"><br /></span></div><div><span>In .NET 4.5 and greater version. <b>HttpClient </b>does not buffer the response by default.</span></div><div><br /></div>azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-73154719950528958602015-03-08T09:54:00.001-07:002015-03-08T09:54:52.394-07:00How to Import/ Insert Picture into Database using SQL Query<div dir="ltr" style="text-align: left;" trbidi="on">
Here is simple script for importing picture into SQL database. You don't need to write a program for importing picture. just follow the below procedure and insert bulk image into database.<br />
<div>
<br /></div>
<div>
(1) Declare a variable with any name and copy the image path into variable.</div>
<div>
(2) Use the cursor to fetch the list of images.</div>
<div>
(3) Get ID from table and insert picture against that ID.</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div>
DECLARE @Path AS VARCHAR(2000)</div>
<div>
SET @Path ='\\192.168.1.1\d\IMG\'</div>
<div>
<br /></div>
<div>
CREATE TABLE #ImageFile (</div>
<div>
id int IDENTITY(1,1)</div>
<div>
,subdirectory nvarchar(512)</div>
<div>
,depth int</div>
<div>
,isfile bit);</div>
<div>
INSERT #ImageFile(subdirectory,depth,isfile)</div>
<div>
EXEC master.sys.xp_dirtree @Path ,0,1;</div>
<div>
select * from #ImageFile</div>
<div>
--drop table #ImageFile</div>
<div>
DECLARE @FileName varchar(100)</div>
<div>
DECLARE @sql_string nvarchar(max) </div>
<div>
Declare @PersonID varchar(50)</div>
<div>
<br /></div>
<div>
DECLARE @PersonImage CURSOR</div>
<div>
SET @PersonImage = CURSOR FOR SELECT subdirectory FROM #ImageFile</div>
<div>
OPEN @PersonImage</div>
<div>
FETCH NEXT FROM @PersonImage INTO @FileName</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>WHILE @@FETCH_STATUS = 0</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>BEGIN</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>SET @PersonID=Replace(@FileName, '.jpg', '')</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>SET @sql_string=N'UPDATE CUSTOMER SET CUST_Image = (SELECT MyImage.* FROM Openrowset(Bulk ' + quotename(@Path + @FileName,nchar(39)) + ', Single_Blob) MyImage) where CUSTOMER_ID = ''' + @PersonID + '''';</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>print @sql_string</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>EXECUTE sp_executesql @sql_string</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>FETCH NEXT FROM @PersonImage INTO @FileName</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>END</div>
<div>
CLOSE @PersonImage</div>
<div>
DEALLOCATE @PersonImage</div>
<div>
drop table #ImageFile</div>
<div>
GO</div>
</div>
<div>
<br /></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-90960377909267757552015-01-03T02:35:00.002-08:002015-01-03T02:35:23.964-08:00DLL file was loaded but the call to DllRegisterServer failed with error code 0x80070005.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="background: white; color: #262626; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-colortransforms: "lumm=85000 lumo=15000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 217;">You may face this error while registering
dlls. </span><b><span style="background: white; color: #595959; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #595959; mso-style-textfill-fill-colortransforms: "lumm=65000 lumo=35000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 166;">“</span></b><b><span style="border: none windowtext 1.0pt; color: #595959; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-border-alt: none windowtext 0in; mso-fareast-font-family: "Times New Roman"; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #595959; mso-style-textfill-fill-colortransforms: "lumm=65000 lumo=35000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 166; padding: 0in;"><DLL file> was
loaded but the call to DllRegisterServer failed with error code 0x80070005</span></b><b><span style="color: #595959; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-fareast-font-family: "Times New Roman"; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #595959; mso-style-textfill-fill-colortransforms: "lumm=65000 lumo=35000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 166;">.</span></b><b><span style="background: white; color: #595959; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #595959; mso-style-textfill-fill-colortransforms: "lumm=65000 lumo=35000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 166;">”</span></b><span style="background: white; color: #595959; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #595959; mso-style-textfill-fill-colortransforms: "lumm=65000 lumo=35000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 166;"> </span></div>
<div class="MsoNormal">
<span style="background: white; color: #262626; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-colortransforms: "lumm=85000 lumo=15000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 217;"><br /></span></div>
<div class="MsoNormal">
<span style="background: white; color: #262626; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-colortransforms: "lumm=85000 lumo=15000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 217;">0x80070005 and 0x80004005 indicates permission issue you must
login with administrator user, </span><span style="background-color: white; color: #262626; font-family: 'Times New Roman', serif; font-size: 13pt; line-height: 115%;">then go to start and press” WIN key” + R.</span></div>
<div class="MsoNormal">
<span style="background-color: white; color: #262626; font-family: 'Times New Roman', serif; font-size: 13pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="background: white; color: #4f6228; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #4F6228; mso-style-textfill-fill-colortransforms: lumm=50000; mso-style-textfill-fill-themecolor: accent3; mso-themecolor: accent3; mso-themeshade: 128;">Type <b>regsvr32 + space + dll path</b>.</span><span style="background: white; color: #262626; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-colortransforms: "lumm=85000 lumo=15000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 217;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background: white; color: #262626; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-colortransforms: "lumm=85000 lumo=15000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 217;"><br /></span></div>
<div class="MsoNormal">
<span style="background: white; color: #262626; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-colortransforms: "lumm=85000 lumo=15000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 217;">And press enter.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; color: #262626; font-family: 'Times New Roman', serif; font-size: 13pt; line-height: 115%;">You will receive message that
dllRegistreServer <DLL File> succeeded.</span></div>
<div class="MsoNormal">
<span style="background: white; color: #262626; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-colortransforms: "lumm=85000 lumo=15000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 217;"><br /></span></div>
<div class="MsoNormal">
<span style="background: white; color: #262626; font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%; mso-ascii-theme-font: major-bidi; mso-bidi-theme-font: major-bidi; mso-hansi-theme-font: major-bidi; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #262626; mso-style-textfill-fill-colortransforms: "lumm=85000 lumo=15000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 217;">If not getting register then do the
following step:<o:p></o:p></span></div>
<div class="MsoNormal">
</div>
<ol style="text-align: left;">
<li><span style="background-color: white; color: #262626; font-family: 'Times New Roman', serif; font-size: 13pt; line-height: 115%; text-indent: -0.25in;">Verify that the file is not read-only.</span></li>
<li><span style="background: white; color: #262626; font-family: 'Times New Roman', serif; font-size: 13pt; line-height: 115%; text-indent: -0.25in;">Go to start up and type <b>CMD</b>, right click on command prompt and
run as administrator.</span></li>
<li><span style="background: white; color: #262626; font-family: 'Times New Roman', serif; font-size: 13pt; line-height: 115%; text-indent: -0.25in;">Then type the same command for dll registration example:</span></li>
<li><span style="background: white; color: #262626; font-family: 'Times New Roman', serif; font-size: 13pt; line-height: 115%; text-indent: -0.25in;"><b>Regsvr32 </b>d:\Test\Test.dll</span></li>
<li><span style="background: white; color: #262626; font-family: 'Times New Roman', serif; font-size: 13pt; line-height: 115%; text-indent: -0.25in;">And press enter.</span></li>
</ol>
<br />
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-3859604666149690642014-12-31T11:58:00.005-08:002014-12-31T12:00:03.131-08:00How to Convert Columns into Row in SQL server.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
Sometime we need to show data in rows that saved in
different columns. For that purpose we can
use two relational operators <span style="color: grey; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;">UNPIVOT </span>and<span style="color: grey; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"> PIVOT </span>to convert data into rows from columns and vice
versa. </div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
In my example, I have a table named
<b>Finger</b><span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"><b>_Print</b> </span>that saved each finger in
different columns. Now, I need to iterate each finger against every person. Here
I convert those columns into rows. This may help you.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> <span style="color: blue;">select</span> ID<span style="color: grey;">,</span>Finger <span style="color: blue;">as</span>
FingerPrint <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> <span style="color: blue;">from </span><span style="color: grey;">(<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> <span style="color: blue;">select</span> Criminal_ID<span style="color: grey;">,</span>RightThumb<span style="color: grey;">,</span>
RightIndex<span style="color: grey;">,</span> RightMiddle<span style="color: grey;">,</span>
RightRing<span style="color: grey;">,</span> RightLittle <span style="color: blue;">from</span>
Finger_Print<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> <span style="color: grey;">)</span> Temp <span style="color: grey;">unpivot<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> </span><span style="color: grey; font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;">(<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> Finger <span style="color: blue;">for</span>
FingerPrint <span style="color: grey;">in</span><span style="color: blue;"> </span><span style="color: grey;">(</span>RightThumb<span style="color: grey;">,</span>
RightIndex<span style="color: grey;">,</span> RightMiddle<span style="color: grey;">,</span>
RightRing<span style="color: grey;">,</span> RightLittle<span style="color: grey;">)<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10.0pt; line-height: 115%; mso-no-proof: yes;"> <span style="color: grey;">)</span>PVT<o:p></o:p></span></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-89028041952968015482014-11-09T23:23:00.001-08:002014-11-09T23:29:00.173-08:00Out of Memory exception. Web Service Exception - Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<b><span style="color: #404040; font-size: 14.0pt; line-height: 115%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-colortransforms: "lumm=75000 lumo=25000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 191;">Out of Memory exception. Web Service Exception -
Client found response content type of 'text/html; charset=utf-8', but expected
'text/xml'.<o:p></o:p></span></b></div>
<div class="MsoNormal">
<b><span style="color: #404040; font-size: 14.0pt; line-height: 115%; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-colortransforms: "lumm=75000 lumo=25000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 191;"><br /></span></b></div>
<div class="MsoNormal">
Today I faced an error whiling sending a request to web
service for a list of detail sale. Everything was fine on client application
and server side hosted web service. I debugged and googled but not find any
solution, just getting the above error.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Then sudden I checked the response that had been more than
200K rows. Oh I find out the reason behind this exception. My response was too
large to accomplish the service. Here I am sharing its solution for you. Keep in
mind these points before hosting your web service. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p><br /></o:p></div>
<div class="MsoListParagraphCxSpFirst" style="margin-left: 38.7pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->1.<span style="font-size: 7pt; font-stretch: normal;">
</span><!--[endif]-->Pick a size that is larger than your largest
request. You can set it 2GB but not recommended.<o:p></o:p></div>
<div class="MsoListParagraphCxSpFirst" style="margin-left: 38.7pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 38.7pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->2.<span style="font-size: 7pt; font-stretch: normal;">
</span><!--[endif]-->Try to reduce your result set in response.<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 38.7pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 38.7pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->3.<span style="font-size: 7pt; font-stretch: normal;">
</span><!--[endif]-->Defined “maxReceivedMessageSize” in your client
application.<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 38.7pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<br /></div>
<br />
<div class="MsoListParagraphCxSpLast" style="margin-left: 38.7pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->4.<span style="font-size: 7pt; font-stretch: normal;">
</span><!--[endif]-->Define timeout response while you have larger
requests. Default time is 90 second which is more than enough for general
purpose.<o:p></o:p></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-29086706979598598062014-09-10T07:15:00.002-07:002014-10-03T08:11:46.291-07:00How to merge Multi Pages tiff files into single tiff in VB.net<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="color: #767171; font-family: Times New Roman, serif; font-size: small;">How to merge </span><span style="color: #767171; font-family: Times New Roman, serif;">Multi Pages</span><span style="color: #767171; font-family: Times New Roman, serif; font-size: small;"> tiff files into single tiff, or how to convert different images into single
tiff file.</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #404040; font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-colortransforms: "lumm=75000 lumo=25000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 191;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #404040; font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-colortransforms: "lumm=75000 lumo=25000"; mso-style-textfill-fill-themecolor: text1; mso-themecolor: text1; mso-themetint: 191;">You may need to merge multi pages tiff into single
tiff file or may be many images into single tiff file. Here I am sharing the
code with you.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">Private</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">Function</span>
MergeImages(<span style="color: blue;">ByVal</span> FileList <span style="color: blue;">As</span> ArrayList, <span style="color: blue;">ByVal</span>
Filename <span style="color: blue;">As</span> <span style="color: blue;">String</span>)
<span style="color: blue;">As</span> <span style="color: blue;">Boolean</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">Try</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">If</span> FileList.Count > 0 <span style="color: blue;">Then</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Dim</span> bmpFirstImage <span style="color: blue;">As</span> Bitmap = <span style="color: blue;">New</span>
Bitmap(FileList.Item(0).ToString)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Dim</span> masterBitmap <span style="color: blue;">As</span> Bitmap = <span style="color: blue;">Nothing</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">If</span> bmpFirstImage <span style="color: blue;">IsNot</span> <span style="color: blue;">Nothing</span> <span style="color: blue;">Then</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
bmpFirstImage.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page,
0)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
masterBitmap = bmpFirstImage<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">End</span> <span style="color: blue;">If</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Dim</span> enc <span style="color: blue;">As</span>
Imaging.Encoder = Encoder.SaveFlag<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Dim</span> info <span style="color: blue;">As</span>
ImageCodecInfo = <span style="color: blue;">Nothing</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Dim</span> ice <span style="color: blue;">As</span>
ImageCodecInfo<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">For</span> <span style="color: blue;">Each</span>
ice <span style="color: blue;">In</span> ImageCodecInfo.GetImageEncoders()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">If</span> ice.MimeType = <span style="color: #a31515;">"image/tiff"</span> <span style="color: blue;">Then</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> info = ice<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">End</span> <span style="color: blue;">If</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Next</span> ice<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Dim</span> ep <span style="color: blue;">As</span>
<span style="color: blue;">New</span> EncoderParameters(1)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
ep.Param(0) = <span style="color: blue;">New</span> EncoderParameter(enc, <span style="color: blue;">CLng</span>(EncoderValue.MultiFrame))<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
masterBitmap.Save(Filename, info, ep)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
ep.Param(0) = <span style="color: blue;">New</span> EncoderParameter(enc, <span style="color: blue;">CLng</span>(EncoderValue.FrameDimensionPage))<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Dim</span> i <span style="color: blue;">As</span>
<span style="color: blue;">Integer</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Try</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">If</span>
bmpFirstImage.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page) > 1 <span style="color: blue;">Then</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">For</span> i = 1 <span style="color: blue;">To</span>
bmpFirstImage.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page) - 1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
bmpFirstImage.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page,
i)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
masterBitmap.SaveAdd(bmpFirstImage, ep)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">Next</span> i<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">End</span> <span style="color: blue;">If</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Catch</span> ex <span style="color: blue;">As</span>
Exception<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">End</span> <span style="color: blue;">Try</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">For</span> index <span style="color: blue;">As</span>
<span style="color: blue;">Integer</span> = 1 <span style="color: blue;">To</span>
FileList.Count - 1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Dim</span> bmpSecondImage <span style="color: blue;">As</span> Bitmap<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
bmpSecondImage = <span style="color: blue;">New</span>
Bitmap(FileList.Item(index).ToString)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">For</span> i = 0 <span style="color: blue;">To</span>
bmpSecondImage.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page) - 1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
bmpSecondImage.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page,
i)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
masterBitmap.SaveAdd(bmpSecondImage, ep)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Next</span> i<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
bmpSecondImage.Dispose()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Next</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
ep.Param(0) = <span style="color: blue;">New</span> EncoderParameter(enc, <span style="color: blue;">CLng</span>(EncoderValue.Flush))<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
masterBitmap.SaveAdd(ep)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
bmpFirstImage.Dispose()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Return</span> <span style="color: blue;">True</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">End</span> <span style="color: blue;">If</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">Catch</span> ex <span style="color: blue;">As</span> Exception<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">Return</span> <span style="color: blue;">False</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">End</span> <span style="color: blue;">Try</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">Return</span> <span style="color: blue;">False</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">End</span> <span style="color: blue;">Function</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-65393851918044941092014-07-21T00:45:00.002-07:002014-10-03T08:11:58.867-07:00Missing a using directive or an assembly reference, how to use NuGet to install missing Assemblies<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<b><span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;">Missing
a using directive or an assembly reference:</span></b><span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;"> </span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlw2KbrIiwIG9-PV6gQJcJQjcrwH1OJ2XGpTiAWjYPm0dOV4ZSof0AL24CfwRJdTt2y9yjt5APOyLE6GBZ1-e1ByBWu_Fj22qlmYbSn8xDcm9CXbExE1cDkoLmAP4XHZWEpJiLtx3yvNX0/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlw2KbrIiwIG9-PV6gQJcJQjcrwH1OJ2XGpTiAWjYPm0dOV4ZSof0AL24CfwRJdTt2y9yjt5APOyLE6GBZ1-e1ByBWu_Fj22qlmYbSn8xDcm9CXbExE1cDkoLmAP4XHZWEpJiLtx3yvNX0/s1600/1.png" height="170" width="320" /></a></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;">An error
describe that you are simply missing a specific namespace or assembly reference
and will just need to add in your project. You can use a package manager in
Dot. Net Framework 4.5 that describe below:
<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;">NuGet
Package Manager:</span></b><span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;"> is a collection of tools that automate
the process of downloading, installing, upgrading, configuring, and removing
packages from a VS Project<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;">NuGet requires that PowerShell 2.0 be installed on
system. PowerShell 2.0 is already installed on Windows 7 and Windows Server
2008 R2.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;">NuGet package manager is rich as it automatically
brought down assemblies into your machine, a reference is added into your
project and everything it needs is merged non-destructively into web.config.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;">You can use NuGut by going to Tools Menu
>>>> Library Package Manager >>>> Manager NuGut
packages for solutions<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCO342SXAB7xbcdyX7L5ZbxIOzhhltnrTqwwzaoAyvCnJrmNQd9CF0Ey2PGPqwqjlYf4mRWme3DZc7Tk1CK131tg-FWUImxroUoA1eSM_AXp9WJULLehEJ5wUDRM58ozh5hdwn5BDnV5pc/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCO342SXAB7xbcdyX7L5ZbxIOzhhltnrTqwwzaoAyvCnJrmNQd9CF0Ey2PGPqwqjlYf4mRWme3DZc7Tk1CK131tg-FWUImxroUoA1eSM_AXp9WJULLehEJ5wUDRM58ozh5hdwn5BDnV5pc/s1600/2.png" height="213" width="320" /></a></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 13.0pt; line-height: 115%;"><br /></span></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-28428468804188585972014-06-27T02:25:00.002-07:002014-10-03T08:12:15.009-07:00UnauthorizedAccessException: Access to the path denied.<div dir="ltr" style="text-align: left;" trbidi="on">
<h1 style="background: white; margin-bottom: .0001pt; margin: 0in; vertical-align: baseline;">
<div class="MsoNormal">
<span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #262626; font-family: 'Times New Roman', serif; font-size: 16pt; line-height: 115%;">Remedy of
UnauthorizedAccessException: Access to the path denied:<o:p></o:p></span></div>
</h1>
<div class="MsoNormal">
<br />
Here are 3 solution to resolve this issue.<br />
<br /></div>
<div class="MsoNormal">
<span style="background: white; color: #111111; font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;">1). Need to modify
the privileges of folder for IIS_IUSRS</span><span style="background: white; font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%;"> account which is member of the Guests group and has security
restrictions</span><span style="background: white; color: #111111; font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;">. You can
add the read/write privileges from security tab.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background: white; color: #111111; font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="background: white; color: #111111; font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="background: white; color: #111111; font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;">2). Use impersonation
to access the local system resources either in code or config file. Add </span><span style="background: rgb(238, 238, 238); font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 115%;"><identity impersonate="true"></span>
in config or machine.config file.\<span style="background: white; color: #111111; font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="background: white; color: #111111; font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;">3). Grant privileges
to Network service user.</span><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-38936852836849771202014-06-18T08:24:00.000-07:002014-10-03T08:12:28.114-07:00How to send an Email using Gmail SMTP server.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="color: #444444;"><span style="font-family: 'Times New Roman', serif; font-size: 14pt; line-height: 115%;">How to send an Email using Gmail SMTP server</span>.</span><span style="color: #1e1c11;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: #1e1c11; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfill-fill-color: #1E1C11; mso-style-textfill-fill-colortransforms: lumm=10000; mso-style-textfill-fill-themecolor: background2; mso-themecolor: background2; mso-themeshade: 26;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;">Hi, here is simple way to send an email using Gmail
SMTP server. Create a form in visual studio with below fields in image.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg_iny37dmW97NAiiu7MhvPslVzUR7SzEjGYo71pnbp2xtiGrdKgWDjJNPfJC_M_MMieS0tC-zXbBCghrN6_UjX-yROUe0w24qwpwDgoEk-ow0JVTCo3lsPzaBulCk4ND-0F3FBDSmL2HN/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg_iny37dmW97NAiiu7MhvPslVzUR7SzEjGYo71pnbp2xtiGrdKgWDjJNPfJC_M_MMieS0tC-zXbBCghrN6_UjX-yROUe0w24qwpwDgoEk-ow0JVTCo3lsPzaBulCk4ND-0F3FBDSmL2HN/s1600/1.png" height="320" width="279" /></a></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;">Add a button to rename it “btnSend”<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;">Now add the following code in btnsend_Click event. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">private</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">void</span>
btnSend_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">try</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">//Create object of System.Net.Mail.MailMessage</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">MailMessage</span> email = <span style="color: blue;">new</span> <span style="color: #2b91af;">MailMessage</span>();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">SmtpClient</span> SmtpServer = <span style="color: blue;">new</span> <span style="color: #2b91af;">SmtpClient</span>(<span style="color: #a31515;">"smtp.gmail.com"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">//Sender Address</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
email.From = <span style="color: blue;">new</span> <span style="color: #2b91af;">MailAddress</span>(txtFrom.Text);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">//Receiver Address</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
email.To.Add(TxtTo.Text);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> email.Subject = TxtSubject.Text;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
email.Body = txtMessage.Text;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">//Email Attachment</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">if</span> (linkLabel1.Text.Trim() != <span style="color: #a31515;">""</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
System.Net.Mail.<span style="color: #2b91af;">Attachment</span>
attachment;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> attachment = <span style="color: blue;">new</span> System.Net.Mail.<span style="color: #2b91af;">Attachment</span>(linkLabel1.Text);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
email.Attachments.Add(attachment);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
SmtpServer.Port = 587; <span style="color: green;">// Gmail SMTP Port</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">//Sender User/Password.</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
SmtpServer.Credentials = <span style="color: blue;">new</span> System.Net.<span style="color: #2b91af;">NetworkCredential</span>(txtUser.Text.Trim(),
txtPassword.Text.Trim());<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
SmtpServer.EnableSsl = <span style="color: blue;">true</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
SmtpServer.Send(email);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
linkLabel1.Text = <span style="color: #a31515;">""</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">MessageBox</span>.Show(<span style="color: #a31515;">"send Successfully."</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span>
ex)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">MessageBox</span>.Show(ex.ToString());<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%;">Test the application and enjoy!!!!<o:p></o:p></span></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-37927705574849103632014-06-05T23:00:00.000-07:002014-10-03T08:01:24.515-07:00What is socket, how to send data over TCP/IP<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
TCP/IP provides end to end connectivity specifying how data should
be formatted, addressed, transmitted, routed, and received at the destination. It
can be used in the internet and in stand-alone private networks.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
TCP (Transmission Control Protocol) is reliable and byte-stream
channel similar to file I/O. It is connection
oriented and bidirectional communication. Used for a large data capacity and persistent
connection. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Socket is known as an internet address, a port number and
end to end protocol.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Before start this, you should be aware about the system
port. For communication you need an open port on server. You can have 65,535
number of TCP port on your system. You can find the open port by using this
command.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Goto Start >>> type cmd in RUN. Write the command in command prompt.<o:p></o:p></div>
<div class="MsoNormal">
<b>netstat -an</b></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVyN_rhCxvOoxxP1rWKXj34pR3jYZTYCDwUuNSV9E2UttWWRLrHJwE4Pmhm7fsbRz14lTXaPjeKsHai6XShihGWyVpGbsS9xScW25BfUOzWOUDPCT1XRho2L-gFN-tlHbYTx0JRk3ffdIw/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVyN_rhCxvOoxxP1rWKXj34pR3jYZTYCDwUuNSV9E2UttWWRLrHJwE4Pmhm7fsbRz14lTXaPjeKsHai6XShihGWyVpGbsS9xScW25BfUOzWOUDPCT1XRho2L-gFN-tlHbYTx0JRk3ffdIw/s1600/2.png" /></a></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
You can also check the specific port by writing this command <o:p></o:p></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
<b>netstat -an|find “13000”<o:p></o:p></b></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
Now work start here. You have a server with known IP address
and open port number. Create two project, one for server that will listen to
the client, and other for client that make requests.<o:p></o:p></div>
<div class="MsoNormal">
Add the following name space in server side code:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Net.Sockets;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Net;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Also add this code in Server side.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">private</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">void</span>
FrmTCPServerListenser_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">TcpListener</span> server = <span style="color: blue;">null</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">try</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">//add your server ip here</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">IPAddress</span> localAddr = <span style="color: #2b91af;">IPAddress</span>.Parse(<span style="color: #a31515;">"127.0.0.1"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// create tcp listener object and pass it
server ip and open port.</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
server = <span style="color: blue;">new</span> <span style="color: #2b91af;">TcpListener</span>(localAddr,
13000);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// start server to listen on the port.</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
server.Start();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// Buffer data</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">Byte</span>[] Requestbytes=<span style="color: blue;">new</span> <span style="color: #2b91af;">Byte</span>[1024];<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">String</span> strData = <span style="color: blue;">null</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// listening Request. </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">while</span> (<span style="color: blue;">true</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// accept connection from client </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">TcpClient</span> client =
server.AcceptTcpClient();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
strData = <span style="color: blue;">string</span>.Empty ;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// Get a stream object for reading and writing</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">NetworkStream</span> stream =
client.GetStream();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">int</span> i;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// receive data from client in loop to the end
of byte</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">while</span> ((i = stream.Read(Requestbytes, 0,
Requestbytes.Length)) != 0)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Convert byte into text</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> strData = System.Text.<span style="color: #2b91af;">Encoding</span>.ASCII.GetString(Requestbytes, 0, i);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> listBox1.Items.Add(strData);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//convert text into byte</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">byte</span>[] msg = System.Text.<span style="color: #2b91af;">Encoding</span>.ASCII.GetBytes(<span style="color: #a31515;">"Message Received"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// send back response to the client.</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> stream.Write(msg, 0,
msg.Length);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// close connection</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
client.Close();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">catch</span> (<span style="color: #2b91af;">SocketException</span>
ez)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">finally</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// Stop listening</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
server.Stop();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now run the server app on server and write this code for
client application.<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">private</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">void</span>
btnSend_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (<span style="color: blue;">string</span>.IsNullOrEmpty(txtMessage.Text.Trim()))<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">return</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">//Create a TCP client</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">TcpClient</span> client = <span style="color: blue;">new</span> <span style="color: #2b91af;">TcpClient</span>(<span style="color: #a31515;">"127.0.0.1"</span>, 13000);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// convert message into byte.</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">Byte</span>[] data = System.Text.<span style="color: #2b91af;">Encoding</span>.ASCII.GetBytes(txtMessage.Text);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">//Network stream for Read and Write </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">NetworkStream</span> Netstream =
client.GetStream();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// Send the message to the connected
TcpServer. </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
Netstream.Write(data, 0, data.Length);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// byte to get the response</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
data = <span style="color: blue;">new</span> <span style="color: #2b91af;">Byte</span>[256];<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">String</span> responseData = <span style="color: #2b91af;">String</span>.Empty;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// read the response.</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">Int32</span> bytes = Netstream.Read(data, 0,
data.Length);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
responseData = System.Text.<span style="color: #2b91af;">Encoding</span>.ASCII.GetString(data,
0, bytes);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">MessageBox</span>.Show(responseData);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// Close stream and connection</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
Netstream.Close();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
client.Close(); <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
On button click event a message will be sent to the server.
<o:p></o:p></div>
<div class="MsoNormal">
Remember that server application must be running before
client apps.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-39372474864994970022014-06-01T23:22:00.002-07:002014-06-01T23:22:19.554-07:00The process cannot access the file because it is being used by another process Error Code 0x8007002<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 30pt;">“The process cannot
access the file because it is being used by another process Error Code
0x8007002.”</span></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<span style="font-family: 'Times New Roman', serif; font-size: 12pt;">The error code state
that there is sharing violation. The port used by your web site may also use by
some other service like Skype or etc. the step to resolve this issue:<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<span style="font-family: 'Times New Roman', serif; font-size: 12pt;">1). Check your web
site port.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<span style="font-family: 'Times New Roman', serif; font-size: 12pt;">2) open command prompt
and write the following command.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<span style="font-family: 'Times New Roman', serif; font-size: 12pt;">For example your web
site use port 80.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeKl-gk_LLpZkmgyt6RbLp7g5XGXTUE0DyRUMzbKKB2VC9xrmE7h8PfX_DKp-_Ixhpjs9O-JDTY3KNt5NUD3LmRGBqB2_VaJ7MWxgIljp30sEhanITaZcDkHtgu3RfhCGTC7CAR5jVDfBJ/s1600/Command.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeKl-gk_LLpZkmgyt6RbLp7g5XGXTUE0DyRUMzbKKB2VC9xrmE7h8PfX_DKp-_Ixhpjs9O-JDTY3KNt5NUD3LmRGBqB2_VaJ7MWxgIljp30sEhanITaZcDkHtgu3RfhCGTC7CAR5jVDfBJ/s1600/Command.png" /></a><span style="font-family: 'Times New Roman', serif; font-size: 12pt;"><!--[if gte vml 1]><v:shapetype
id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_i1027" type="#_x0000_t75"
style='width:384pt;height:195pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\azamkhan\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title="Command"/>
</v:shape><![endif]--><!--[if !vml]--><img src="file:///C:\Users\azamkhan\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png" v:shapes="Picture_x0020_1" /><!--[endif]--></span><span style="font-family: 'Times New Roman', serif; font-size: 12pt;"> </span><span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 30pt;">And then Press enter.
In below image, you can find the process
blocking your web site.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxguWvp68apmw6yUEJm3If3z7rTwbiKJgssyC7SbmSSNYe9UqhQQi-5tb-J-gnpdf1XvDCSpIIwztqXFvvkjzHCidLS-FiXOA14wEc6mecSNSCkvpfy0c5SOFZNYK7hoskXLuwTHfhhGfz/s1600/command+2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxguWvp68apmw6yUEJm3If3z7rTwbiKJgssyC7SbmSSNYe9UqhQQi-5tb-J-gnpdf1XvDCSpIIwztqXFvvkjzHCidLS-FiXOA14wEc6mecSNSCkvpfy0c5SOFZNYK7hoskXLuwTHfhhGfz/s1600/command+2.png" /></a></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<br /></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<span style="font-family: 'Times New Roman', serif; font-size: 12pt;">3). Now open the task
manager. click on select column in view menu and s</span><span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 30pt;">elect the PID column
from list.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuP7aF8_c2S1pL347i-qinLp8Eb7olazFMTeKCSjz6xD3fb-PQJhCvR0rI7CAqVvjiXneSyQjBIdvDe3BK0P7_PqFWHE-sEDd-PAi07B0nHbg15um1KwYIYsyhOe06BwPgfxZlqgVz4J3t/s1600/process.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuP7aF8_c2S1pL347i-qinLp8Eb7olazFMTeKCSjz6xD3fb-PQJhCvR0rI7CAqVvjiXneSyQjBIdvDe3BK0P7_PqFWHE-sEDd-PAi07B0nHbg15um1KwYIYsyhOe06BwPgfxZlqgVz4J3t/s1600/process.png" /></a></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<br /></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<br /></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<br /></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<br /></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<br /></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<br /></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<br /></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<br /></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<br /></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 30pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 30pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 30pt;">4). Now in process
tab you can see the process id with associated apps that blocking you web site.</span></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<span style="font-family: 'Times New Roman', serif; font-size: 12pt;">5). Kill the apps to start the web site.<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbdmaX7tLKpiyxW-Yb23qbDwsbGQn1D_LaDFGLwy2BfLFIvECQEG8IW0gfhcXmtlxtvNYxcKg07V4SzjpISxau-nZ5K2sCp5FrDKMFSLztuEBu_-U3xZjHTL9ZLZOi1zZv3dH60C9lQmgq/s1600/Process2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbdmaX7tLKpiyxW-Yb23qbDwsbGQn1D_LaDFGLwy2BfLFIvECQEG8IW0gfhcXmtlxtvNYxcKg07V4SzjpISxau-nZ5K2sCp5FrDKMFSLztuEBu_-U3xZjHTL9ZLZOi1zZv3dH60C9lQmgq/s1600/Process2.png" /></a></div>
<div class="MsoNormal" style="line-height: 30.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 1; vertical-align: top;">
<br /></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-68128835595612861182014-05-28T00:01:00.003-07:002014-10-03T08:09:17.596-07:00How to send and Received HTTP Request/Response<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
Today we will talk about HTTP request, how to send and
receive http request. We can use WebClient and HttpwebRequest to send the
Request, but there are some advantages of HttpWebRequest over WebClient.<o:p></o:p></div>
<div class="MsoNormal">
We mostly used the webclient for uploading and downloading
the files, but with HttpwebRequest we can do a lot. We can set it request
timeout and content Type that would be handled on service side.<o:p></o:p></div>
<div class="MsoNormal">
Please comment if like this post, so that i continued
posting.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
Here is code for client side. you can use it with window
form.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">private</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">void</span>
btnSend_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Create new Datatable</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataTable</span> dtEmployee = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataTable</span>(<span style="color: #a31515;">"Employee"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Add Columns</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataColumn</span> DColID = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataColumn</span>(<span style="color: #a31515;">"Emp_ID"</span>,
System.<span style="color: #2b91af;">Type</span>.GetType(<span style="color: #a31515;">"System.Int32"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dtEmployee.Columns.Add(DColID);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataColumn</span> DColName = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataColumn</span>(<span style="color: #a31515;">"Name"</span>,
System.<span style="color: #2b91af;">Type</span>.GetType(<span style="color: #a31515;">"System.String"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dtEmployee.Columns.Add(DColName);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataColumn</span> DColDepart = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataColumn</span>(<span style="color: #a31515;">"Department"</span>,
System.<span style="color: #2b91af;">Type</span>.GetType(<span style="color: #a31515;">"System.String"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dtEmployee.Columns.Add(DColDepart);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Adding data</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dtEmployee.Rows.Add(<span style="color: #a31515;">"1201"</span>,
<span style="color: #a31515;">"Wasi"</span>, <span style="color: #a31515;">"IT"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dtEmployee.Rows.Add(<span style="color: #a31515;">"1301"</span>,
<span style="color: #a31515;">"Shref"</span>, <span style="color: #a31515;">"HR"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataSet</span> dsRequest = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataSet</span>();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dsRequest.Tables.Add(dtEmployee);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Now create an Object of System.IO.MemoryStream</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">MemoryStream</span> ms = <span style="color: blue;">new</span>
<span style="color: #2b91af;">MemoryStream</span>();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Write dataset into memorystream</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dsRequest.WriteXml(ms, <span style="color: #2b91af;">XmlWriteMode</span>.WriteSchema);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//string URL =
@"http://localhost/TestProject/Test.aspx";</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> URL = <span style="color: #a31515;">@"http://localhost:59580/Default.aspx"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Create an object of HTTPWebRequest and pass it URL</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">HttpWebRequest</span> httpReq = (<span style="color: #2b91af;">HttpWebRequest</span>)<span style="color: #2b91af;">WebRequest</span>.Create(URL);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//convert memory stream into byte to assign it to
httpwebrequest</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Byte</span>[] ReqByte = ms.ToArray();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Now you can take advantages of using HTTPWebRequest over
WebClient. you can set its different properties</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
httpReq.ContentLength = ReqByte.Length;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
httpReq.Timeout = 10000;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
httpReq.ContentType = <span style="color: #a31515;">"xml"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
httpReq.Method = <span style="color: #a31515;">"POST"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
httpReq.KeepAlive = <span style="color: blue;">false</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Create an object of Stream and write the byte into it.</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Stream</span> ReqStream = httpReq.GetRequestStream();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> ReqStream.Write(ReqByte, 0, ReqByte.Length);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
ReqStream.Close();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Create an object of HttpWebResponse to Read the Response</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">HttpWebResponse</span> httpResp = (<span style="color: #2b91af;">HttpWebResponse</span>)httpReq.GetResponse();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Assign Response Stream to Stream Reader</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">StreamReader</span> RespStreamReader = <span style="color: blue;">new</span> <span style="color: #2b91af;">StreamReader</span>(httpResp.GetResponseStream());<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span> strResponse = RespStreamReader.ReadToEnd();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Code that will be used in page load event of an aspx page
(Web Project).<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">protected</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">void</span> Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span>
e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Validate the contenttype that you send from client side</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">if</span> (Request.ContentType.ToString().Equals(<span style="color: #a31515;">"xml"</span>))<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">//Create an object of streamreader and read
the page request inputstream</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">StreamReader</span> ReqStrmReader = <span style="color: blue;">new</span> <span style="color: #2b91af;">StreamReader</span>(Page.Request.InputStream);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">string</span> strRequest =
ReqStrmReader.ReadToEnd();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">if</span> (!<span style="color: blue;">string</span>.IsNullOrEmpty(strRequest))<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">//Convert the Reqeust string into byte</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Byte</span>[]
btReq = System.Text.<span style="color: #2b91af;">Encoding</span>.ASCII.GetBytes(strRequest);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">//Create an object of Memory Stream and assign
these byte to it.</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">MemoryStream</span> ms = <span style="color: blue;">new</span> <span style="color: #2b91af;">MemoryStream</span>(btReq);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">//Create a dataset and assign this stream to
it</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: #2b91af;">DataSet</span> dsReq = <span style="color: blue;">new</span> <span style="color: #2b91af;">DataSet</span>();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dsReq.ReadXml(ms);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
Response.Write(<span style="color: #a31515;">"Dataset Received"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">// that is the end. now you can use this dataset
anywhere else.</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<br /></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-72879339361565444382014-05-27T07:04:00.003-07:002014-10-03T08:09:38.681-07:00How to Hide Column in DataTable or GridView<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
If you want to hide column in datatable dynamically, here is
the simple code for that.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
You need to add this code in load event or anywhere else.<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: Consolas; font-size: 9.5pt;">// Create new Datatable</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataTable</span> dtStudent = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataTable</span>(<span style="color: #a31515;">"Student"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Add Columns</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataColumn</span> DColStdID = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataColumn</span>(<span style="color: #a31515;">"Stud_ID"</span>,
System.<span style="color: #2b91af;">Type</span>.GetType(<span style="color: #a31515;">"System.Int32"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// hide column in datatable. this will not display in
DataGridView</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="background: yellow; mso-highlight: yellow;">DColStdID.ColumnMapping = <span style="color: #2b91af;">MappingType</span>.Hidden;</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="font-family: Consolas; font-size: 13px;">dtStudent</span><span style="font-family: Consolas; font-size: 9.5pt;">.Columns.Add(DColStdID);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataColumn</span> DColStdName = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataColumn</span>(<span style="color: #a31515;">"Name"</span>,
System.<span style="color: #2b91af;">Type</span>.GetType(<span style="color: #a31515;">"System.String"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="font-family: Consolas; font-size: 13px;">dtStudent</span><span style="font-family: Consolas; font-size: 9.5pt;">.Columns.Add(DColStdName);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataColumn</span> DColStdClass = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataColumn</span>(<span style="color: #a31515;">"Class"</span>,
System.<span style="color: #2b91af;">Type</span>.GetType(<span style="color: #a31515;">"System.String"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="font-family: Consolas; font-size: 13px;">dtStudent</span><span style="font-family: Consolas; font-size: 9.5pt;">.Columns.Add(DColStdClass);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Adding data</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="font-family: Consolas; font-size: 13px;">dtStudent</span><span style="font-family: Consolas; font-size: 9.5pt;">.Rows.Add(<span style="color: #a31515;">"100"</span>, <span style="color: #a31515;">"Wasi"</span>, <span style="color: #a31515;">"2nd"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="font-family: Consolas; font-size: 13px;">dtStudent</span><span style="font-family: Consolas; font-size: 9.5pt;">.Rows.Add(<span style="color: #a31515;">"101"</span>, <span style="color: #a31515;">"Shref"</span>, <span style="color: #a31515;">"3rd"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dataGridView1.DataSource = </span><span style="font-family: Consolas; font-size: 13px;">dtStudent</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now add the datagridview on form. And run the code.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi51n0AiHA9mEtn5mJHlHgh6gulXpYa-tGbW4Im4azOnUJo4qS_j_dk6s39HnpB1WcY-9WJPDf-wwt6_QDhJ7DG7ktbzec7-N-EZ5hrle0IsyJlvTF-gPfBhdy7mG-vdAA1PDr7fw7Ri6mt/s1600/Hidding+column+in+datatable.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi51n0AiHA9mEtn5mJHlHgh6gulXpYa-tGbW4Im4azOnUJo4qS_j_dk6s39HnpB1WcY-9WJPDf-wwt6_QDhJ7DG7ktbzec7-N-EZ5hrle0IsyJlvTF-gPfBhdy7mG-vdAA1PDr7fw7Ri6mt/s1600/Hidding+column+in+datatable.png" /></a></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<!--[if gte vml 1]><v:shapetype
id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_i1025" type="#_x0000_t75"
style='width:365.25pt;height:168.75pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\azamkhan\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title="Hidding column in datatable"/>
</v:shape><![endif]--><!--[if !vml]--><img src="file:///C:\Users\azamkhan\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png" v:shapes="Picture_x0020_1" /><!--[endif]--><o:p></o:p></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-15025438226662070532014-05-27T06:13:00.000-07:002014-10-03T08:10:00.911-07:00How to add columns and row in datatable.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
A simple way to adding columns and rows in Datatable<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: Consolas; font-size: 9.5pt;">// Create a new Datatable</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataTable</span> dtEmployee = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataTable</span>(<span style="color: #a31515;">"Employee"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">// Define Column</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataColumn</span> DColEmpID = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataColumn</span>(<span style="color: #a31515;">"Emp_ID"</span>,
System.<span style="color: #2b91af;">Type</span>.GetType(<span style="color: #a31515;">"System.Int32"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
DColEmpID.AllowDBNull = <span style="color: blue;">false</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
DColEmpID.Caption = <span style="color: #a31515;">"ID"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
DColEmpID.AllowDBNull = <span style="color: blue;">false</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Adding Columns</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dtEmployee.Columns.Add(DColEmpID);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataColumn</span> DColName = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataColumn</span>(<span style="color: #a31515;">"Emp_Name"</span>,
System.<span style="color: #2b91af;">Type</span>.GetType(<span style="color: #a31515;">"System.String"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
DColName.AllowDBNull = <span style="color: blue;">false</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
DColName.Caption = <span style="color: #a31515;">"Name"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dtEmployee.Columns.Add(DColName);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataColumn</span> DColDept = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataColumn</span>(<span style="color: #a31515;">"Department_ID"</span>,
System.<span style="color: #2b91af;">Type</span>.GetType(<span style="color: #a31515;">"System.Int32"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
DColDept.AllowDBNull = <span style="color: blue;">false</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
DColDept.Caption = <span style="color: #a31515;">"Department_ID"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
DColDept.DefaultValue = <span style="color: #a31515;">"1"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dtEmployee.Columns.Add(DColDept);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">DataColumn</span> DColSalary = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataColumn</span>(<span style="color: #a31515;">"Salary"</span>,
System.<span style="color: #2b91af;">Type</span>.GetType(<span style="color: #a31515;">"System.Decimal"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
DColSalary.Caption = <span style="color: #a31515;">"Salary"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
DColSalary.DefaultValue = <span style="color: #a31515;">"0.0"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dtEmployee.Columns.Add(DColSalary);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//Add data into columns</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dtEmployee.Rows.Add(<span style="color: #a31515;">"1"</span>, <span style="color: #a31515;">"Jacky"</span>, <span style="color: #a31515;">"21"</span>,
<span style="color: #a31515;">"5000"</span>);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
dtEmployee.Rows.Add(<span style="color: #a31515;">"2"</span>, <span style="color: #a31515;">"Franky"</span>, <span style="color: #a31515;">"21"</span>,
<span style="color: #a31515;">"7000"</span>);<o:p></o:p></span></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-61319004149459557812014-05-27T04:25:00.002-07:002014-10-03T08:10:18.135-07:00Invalid length for a Base-64 char array<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<b><span style="color: red;">Invalid length for a Base-64 char array.<o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
First of all check your string length whenever you face this error.<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
It came when you use to convert string into byte using<span style="font-family: 'Times New Roman', serif; font-size: 13.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-fareast-font-family: "Times New Roman";">Convert</span><span style="font-family: Consolas; font-size: 9.5pt;">.FromBase64String.</span><span style="font-family: 'Times New Roman', serif; font-size: 13.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
This method takes the array of char from your
string. If char length < 64 then it will throw the above exception.<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
You must need to check
the char length before calling this.<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
You can create this
exception like:<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: Consolas; font-size: 9.5pt;">// is OK</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"><span style="color: #2b91af;">Byte</span>[] bt1=<span style="color: #2b91af;">Convert</span>.FromBase64String(<span style="color: #a31515;">"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: Consolas; font-size: 9.5pt;">// will throw Exception</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Byte</span><span style="font-family: Consolas; font-size: 9.5pt;">[] bt2 = <span style="color: #2b91af;">Convert</span>.FromBase64String(<span style="color: #a31515;">"ABCDEFGHIJKLMNOPQRSTUVWXYZ"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
It will ignore the space
<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: green; font-family: Consolas; font-size: 9.5pt;">// will also throw Exception because of
Space</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">Byte</span>[] bt2 = <span style="color: #2b91af;">Convert</span>.FromBase64String(<span style="color: #a31515;">"ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJ"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<br /></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-83618289309023010402014-05-25T22:47:00.002-07:002014-10-03T08:10:36.044-07:00How to get Latest Modified or Created file in Directory ( A recursive search method)<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><br /></span></div>
<div class="MsoNormal">
Today I want to share little knowledge that how we can get
the latest file in different folder with same name.<o:p></o:p></div>
<div class="MsoNormal">
For example we have text file with name employee ID + extension
(.txt) in different folders may be department wise or deputation wise. Now the task
is how to get the latest file of an employee from different folder.<o:p></o:p></div>
<div class="MsoNormal">
Here is the function that gives you the file.<o:p></o:p></div>
<div class="MsoNormal">
You must import (vb.net)/ Using (C#) the following
assemblies:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">Imports</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.IO<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">Imports</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Linq<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now call the function and passed it employee id and root
directory.<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">Private</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">Function</span>
GetLatestFile(<span style="color: blue;">ByVal</span> EmpId <span style="color: blue;">As</span> <span style="color: blue;">String</span>, <span style="color: blue;">ByVal</span> rootDirectory <span style="color: blue;">As</span>
<span style="color: blue;">String</span>) <span style="color: blue;">As</span> <span style="color: blue;">String</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">''Get Direcotry list order by CreateTime Desc </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">Dim</span> strPath
<span style="color: blue;">As</span> <span style="color: blue;">String</span> = <span style="color: blue;">String</span>.Empty<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">Dim</span> directories <span style="color: blue;">As</span> <span style="color: #2b91af;">IEnumerable</span>(<span style="color: blue;">Of</span> <span style="color: #2b91af;">DirectoryInfo</span>) = <span style="color: blue;">From</span>
path <span style="color: blue;">In</span> System.IO.<span style="color: #2b91af;">Directory</span>.GetDirectories(rootDirectory)
<span style="color: blue;">Let</span> directory = <span style="color: blue;">New</span>
System.IO.<span style="color: #2b91af;">DirectoryInfo</span>(path) <span style="color: blue;">Order</span> <span style="color: blue;">By</span>
directory.LastAccessTime <span style="color: blue;">Descending</span> <span style="color: blue;">Select</span> directory<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">If</span> directories <span style="color: blue;">IsNot</span> <span style="color: blue;">Nothing</span> <span style="color: blue;">Then</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">For</span> <span style="color: blue;">Each</span> drIno <span style="color: blue;">As</span> <span style="color: #2b91af;">DirectoryInfo</span> <span style="color: blue;">In</span> directories<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">If</span> <span style="color: #2b91af;">File</span>.Exists(drIno.FullName
+ <span style="color: #a31515;">"\"</span> + EmpId + <span style="color: #a31515;">".txt"</span>) <span style="color: blue;">Then</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
strPath = drIno.FullName + <span style="color: #a31515;">"\"</span>
+ EmpId + <span style="color: #a31515;">".txt"</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">Exit For</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">End</span> <span style="color: blue;">If</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">Next</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">End</span> <span style="color: blue;">If</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">Return</span> strPath<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">End</span> <span style="color: blue;">Function<o:p></o:p></span></span></div>
</div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-8187807847245362292014-05-23T06:43:00.002-07:002014-10-03T08:10:53.527-07:00IIS log Timer_ConnectionIdle<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
Don’t worry when you find this error in IIS log files
"Timer_ConnectionIdle". <o:p></o:p></div>
<div class="MsoNormal">
the error come when no data received within timeout period,
mostly in case of web services where multiple user try to submit request, you
just need to set MinFileBytesPerSec property or simply reset the IIS will solve
the problem.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Here with steps that strongly recommended to resolve this
issue permanently.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
1) Check your connection pool defines in config file.<o:p></o:p></div>
<div class="MsoNormal">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBbqeIYCu6-wZPcpBsKvqR4q4tzGWlmwm-ExmLIoyD86eAaASKdLDS71pyNDRCDrG6QOxx_-1Qy6jJZ6yck8QSIPW2WLs6VRElNLJhUCWl-lnudv4c5ehdDIjJCJjtiWQTXGOT8wCj1uYV/s1600/config.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBbqeIYCu6-wZPcpBsKvqR4q4tzGWlmwm-ExmLIoyD86eAaASKdLDS71pyNDRCDrG6QOxx_-1Qy6jJZ6yck8QSIPW2WLs6VRElNLJhUCWl-lnudv4c5ehdDIjJCJjtiWQTXGOT8wCj1uYV/s1600/config.JPG" /></a>2) Set MinFileBytesPerSec property of IIS.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Kindly comment if find it helpful.</div>
<o:p></o:p></div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0tag:blogger.com,1999:blog-8772831926848695794.post-14871251688773009152014-05-22T22:24:00.004-07:002014-10-03T08:11:07.679-07:00Min (x) must be less than or equal to max (-1) in a Range object.<div dir="ltr" style="text-align: left;" trbidi="on">
Today i faced the error Min (4) must be less than or equal to max (-1) in a Range object. while doing query on data table.<br />
<br />
dtFinal.select(<span style="color: #cc0000;">"Person_ID="</span> + strPersonID )<br />
<br />
After investigation, I find out that column person_id in datatable is string type. simply use single quotes in above statement<br />
resolve the issue.<br />
<br />
dtFinal.select(<span style="color: #cc0000;">"Person_ID='"</span> + strPersonID + <span style="color: #cc0000;">"'"</span>)<br />
<br />
<br />
<br /></div>
azamhttp://www.blogger.com/profile/09492216852323782700noreply@blogger.com0