Thursday, April 4, 2024

Open default email app in .NET MAUI

Sample Code:

 if (Email.Default.IsComposeSupported)

{

    string subject = "Hello!";

    string body = "Excellent!";

    string[] recipients = new[] { "Support@3MbSolutions.com", "Marketing@3MbSolutions.com" };


    var message = new EmailMessage

    {

        Subject = subject,

        Body = body,

        BodyFormat = EmailBodyFormat.PlainText,

        To = new List<string>(recipients)

    };


    await Email.Default.ComposeAsync(message);

}

If your project's Target Android version is set to Android 11 (R API 30) or higher, you must update your Android Manifest with queries that use Android's  package visibility requirements.

In the Platforms/Android/AndroidManifest.xml file, add the following queries/intent nodes in the manifest node:

<queries>

  <intent>

    <action android:name="android.intent.action.SENDTO" />

    <data android:scheme="mailto" />

  </intent>

</queries>


Monday, December 5, 2022

FIX :ERROR ITMS-90717: "INVALID APP STORE ICON. THE APP STORE ICON IN THE ASSET CATALOG IN '_____' CAN'T BE TRANSPARENT NOR CONTAIN AN ALPHA CHANNEL

 

When you upload the archive to the App Store using the tool from Xcode, you may get the following error:

1

ERROR ITMS-90717: "Invalid App Store Icon. The App Store Icon in the asset catalog in '_____.app' can't be transparent nor contain an alpha channel.

Reason: Your Icon image has feature: Alpha

Solution: Make a PNG without an alpha channel.

How to fix it:

Open file: Assets.xcassets From Runner > Runner > Assets.xcassets
1. Select the AppIcon item, scroll down to the bottom to select the image size 1024 pt.

2.Right-click : Open in Finder
3. Double Click on that photo to open
4. Select File > Export...
5. In the Export screen: Untick Alpha, save the image file 

6. Replace the entire App icon with that
Image 

7. Archive and Distribute => OK

 

Tuesday, November 1, 2022

Generate Random Numbers in .NET6

 We can generate random number using the following code:

Console.WriteLine("Generate Randoms!");

var objRandom = new Random();

var myValue = objRandom.Next();

Console.WriteLine($"{myValue}");

In the above example, you obtain an int number as result.

You can use the methods NextBytes and NextDouble to obtain the results to obtain random bytes or random doubles values.


In .NET 6 you can use the class RandomNumberGenerator present in the namespace System.Security.Cryptography.


  Console.WriteLine("Generate Randoms in .NET 6!");

   var objRandom = RandomNumberGenerator.Create();

   var objBytes = new byte[sizeof(int)]; // 4 bytes

   objRandom.GetNonZeroBytes(objBytes);

    var myResult = BitConverter.ToInt32(objBytes, 0);

    Console.WriteLine($"{myResult}");

Friday, October 28, 2022

Copy to Clipboard using Javascript

 Copying the text to clipboard makes it easier to use the web page, so users will definitely like this functionality. You can achieve it using JavaScript.

Note: For this function to work in production environment, make sure your website has SSL Certificate

Sample:

  <asp:Button ID="btnCopyResult" Visible ="false"   OnClientClick="CopyToClipBoard();"   class="btn btn-primary btn-sm"   runat="server" Text="Copy Result" />  

 <script type="text/javascript">

  function CopyToClipBoard()

 {

var sData = "Copy ME!";

try 

{

      navigator.clipboard.writeText(sData);

     return true;

 }

 catch (err) 

{

    alert('Could not write to clipboard', err);

    return false;

}

}

Monday, October 24, 2022

Means of Persisting Form Data

 There are many ways of persisting form data after the form has been submitted. Some of the more popular ways include the following:

  • The values of form fields can be stored in the Session object. Data can be added to the Session object with a line like this (in ASP.NET):

    Session("Name") = "Mike Davis";
    

    Session information can be stored in various locations: inside the ASP.NET runtime process, inside a dedicated Microsoft Windows® service, or inside a Microsoft SQL Server™ database. However, using the Session object, in any of these locations, is costly in server memory. In addition, you have to read the values out of session and put them back into the form on each page load. This routine code bulks up your pages.

  • Another option to persisting data is to duplicate your form content in a hidden field that is posted back to the server. The HiddenField control is used to store a value that needs to be persisted across posts to the server. It is rendered as an <input type= "hidden"/> element. Normally view state, session state, and cookies are used to maintain the state of a Web Forms page.


Error: 1260 This Program is Blocked by Group Policy Plesk

 1026 This program is blocked by group policy. For more information, contact the system administrator.(GoDaddy server):

We can also eradicate the error “1026 This program block by group policy. For more information, contact the system administrator.” while hosting the asp.net mvc application published copy to the GoDaddy account. We can solve the issues by removing all of the contents inside the system.codedom tag in web.config file. 

Go to web.config file in the project folder then search for system.codedom tag and removed all the contents inside the system.codedom tag. 

Open default email app in .NET MAUI

Sample Code:  if (Email.Default.IsComposeSupported) {     string subject = "Hello!";     string body = "Excellent!";    ...