<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rasma Raj</title>
    <description>The latest articles on DEV Community by Rasma Raj (@rasmaraj).</description>
    <link>https://dev.to/rasmaraj</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F804403%2F83d6700e-2113-4719-ad37-e32c51db2a24.jpg</url>
      <title>DEV Community: Rasma Raj</title>
      <link>https://dev.to/rasmaraj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rasmaraj"/>
    <language>en</language>
    <item>
      <title>Find number of lines of code  in a .Net project</title>
      <dc:creator>Rasma Raj</dc:creator>
      <pubDate>Fri, 04 Mar 2022 07:00:17 +0000</pubDate>
      <link>https://dev.to/rasmaraj/find-number-of-lines-of-code-in-a-net-project-151a</link>
      <guid>https://dev.to/rasmaraj/find-number-of-lines-of-code-in-a-net-project-151a</guid>
      <description>&lt;p&gt;I had a requirement to find the number of lines in a major project which has been completed with .Net 2019.&lt;/p&gt;

&lt;p&gt;The way I found the number of lines of  coding is -&lt;/p&gt;

&lt;p&gt;Step 1: Open the project &lt;br&gt;
step 2: View &amp;gt; Other Windows &amp;gt; Code Metrics Results&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--djKaNyNG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r09inmwpgcbpwsrs6yuk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--djKaNyNG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r09inmwpgcbpwsrs6yuk.png" alt="![Find number of lines of code in a .Net project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rzc2p2o4mceb2dh3f9jd.png)&amp;lt;br&amp;gt;
 " width="644" height="983"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;step 3 :&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--paBXwQUB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gwvfdh8y1hy4aqa3k1zu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--paBXwQUB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gwvfdh8y1hy4aqa3k1zu.png" alt="Code Matrics Result" width="880" height="163"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LnQ9ozA7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o6odxb7lncrn7kaw5sbp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LnQ9ozA7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o6odxb7lncrn7kaw5sbp.png" alt="Code Matrics Result View" width="880" height="137"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>dotnet</category>
    </item>
    <item>
      <title>Download multiple files in zipped format</title>
      <dc:creator>Rasma Raj</dc:creator>
      <pubDate>Tue, 15 Feb 2022 07:09:55 +0000</pubDate>
      <link>https://dev.to/rasmaraj/download-multiple-files-in-zipped-format-57m9</link>
      <guid>https://dev.to/rasmaraj/download-multiple-files-in-zipped-format-57m9</guid>
      <description>&lt;p&gt;Use  System.IO.Compression class for compressing the file in .Zip format&lt;/p&gt;

&lt;p&gt;=&amp;gt; Create a instance of the MemoryStream .&lt;br&gt;
=&amp;gt; Create Zipped folder in memory&lt;br&gt;
=&amp;gt; Use archive.CreateEntry method to add files into the zip folder&lt;br&gt;
=&amp;gt; Add content into the created files&lt;br&gt;
=&amp;gt; Now the zipped folder with all files stored in the memory    instance&lt;br&gt;
=&amp;gt; Then return the file , the save As file dialogue appears in the   window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System.IO.Compression;

public void DownloadFilesInZip()
{
 var _ListOfFiles=new List&amp;lt;Tuple&amp;lt;int,byte[],string&amp;gt;&amp;gt;()
{
new Tuple&amp;lt;int,byte[],string&amp;gt;(1,F1,FileName1),
new Tuple&amp;lt;int,byte[],string&amp;gt;(2,F2,FileName2),
new Tuple&amp;lt;int,byte[],string&amp;gt;(3,F3,FileName3)
};

using (MemoryStream ms = new MemoryStream())
{
using (var archive = new ZipArchive(ms, ZipArchiveMode.Create, true))
     {
     foreach (var _file in _ListOfFiles)
        {
     var entry = archive.CreateEntry(_file.Item3, CompressionLevel.Fastest);

     using (var zipStream = entry.Open())
         {
zipStream.Write(_file .Item2, 0, _file .Item2.Length);
         }

        }
    }
string _FileName = $"DateTime.Now.ToString("ddMMyyyy")}.zip";
return File(ms.ToArray(), "application/zip", _FileName);
                    }

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>mvc</category>
      <category>csharp</category>
    </item>
    <item>
      <title>HttpPostedFileBase</title>
      <dc:creator>Rasma Raj</dc:creator>
      <pubDate>Wed, 09 Feb 2022 07:02:38 +0000</pubDate>
      <link>https://dev.to/rasmaraj/httppostedfilebase-3k9g</link>
      <guid>https://dev.to/rasmaraj/httppostedfilebase-3k9g</guid>
      <description>&lt;p&gt;My requirement was to send the file through the mail and save the file in binary format.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Issue faced&lt;/strong&gt;&lt;br&gt;
File content length became 0 after converted to the byte array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;1) Created a class with properties&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Model_File
    {
        public string FileName { get;private set; }
        public string ContentType { get; private set; }
        public byte[] Contents { get; private set; }
        public Model_File(string FileName, string ContentType, byte[] Contents)
        {
            this.FileName = FileName;
            this.ContentType = ContentType;
            this.Contents = Contents;
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Read all the file using binary reader and store  in a  List of class&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static List&amp;lt;Model_File&amp;gt; Get_File(HttpPostedFileBase[] postedfiles)
{

var Result =new List&amp;lt;Model.Model_File&amp;gt;();
if (postedfiles.Length != 0)
            {
                foreach (var item in postedfiles)
                {
                    if (item.ContentLength != 0)
                    {
                        var R = Try_Byte(item, "Attachment");                       
                        if (R != null)
                        {
                            Result .Add(R);                            
                        }
                    }

                }
            }
return Result;
}

private static Model_File Try_Byte(HttpPostedFileBase F,string CType)
        {
            Model.Model_File Result = null;
            if (F != null &amp;amp;&amp;amp; F.ContentLength!=0)
            {
                using (BinaryReader dr = new BinaryReader(F.InputStream))
                {
                    byte[] content = dr.ReadBytes(F.ContentLength);
                    return new Model_File(F.FileName, CType, content);
                }
            }
            return Result;
        }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) To Send these files in mail - Create the attachment and add to the mail message&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void Send(List&amp;lt;Model_File&amp;gt; _Files)
{
MailMessage msg = new MailMessage()

if(_Files.count!=0)
{
_Files.foreach(delegate(Model_File F){

var _Attachment=Get(F)
if(_Attachment!=mull){
msg.Attachments.Add(_Attachment);
}

});
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private static Attachment Get(Model_File F)
        {
            if (F != null &amp;amp;&amp;amp; F.Contents!=null &amp;amp;&amp;amp; F.Contents.Length!=0 &amp;amp;&amp;amp; !string.IsNullOrWhiteSpace(F.ContentType))
            {
               return new Attachment(new MemoryStream(F.Contents), F.FName);
            }
            return null;
        }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4) Get the result- List of Model_Files objects and inserted to the database in varbinary format.For that I created the column in table with an attribute varbinary(max).&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Issue *&lt;/em&gt;&lt;br&gt;
Cant covert to varbinary to varchar - this error got when added like a normal parameter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;br&gt;
Then i  declared the parameter  as below.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Command.Parameters.Add("@Attachment", System.Data.SqlDbType.VarBinary, -1).Value = (A.Contents == null ? (object)DBNull.Value : (object)A.Contents );&lt;/code&gt;&lt;/p&gt;

</description>
      <category>csharp</category>
    </item>
  </channel>
</rss>
