첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.15MB

▶ MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="TestProject.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <StackLayout
        HorizontalOptions="Center"
        VerticalOptions="Center"
        Spacing="10">
        <Button x:Name="createTestFileButton"
            HorizontalOptions="Center"
            Text="테스트 파일 생성하기" />
        <Button x:Name="shareFileButton"
            HorizontalOptions="Center"
            Text="복수 파일 공유하기" />
    </StackLayout>
</ContentPage>

 

728x90

 

▶ MainPage.xaml.cs

namespace TestProject;

/// <summary>
/// 메인 페이지
/// </summary>
public partial class MainPage : ContentPage
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Field
    ////////////////////////////////////////////////////////////////////////////////////////// Private

    #region Field

    /// <summary>
    /// 파일명1
    /// </summary>
    private string fileName1 = "sample1.txt";

    /// <summary>
    /// 파일명2
    /// </summary>
    private string fileName2 = "sample2.txt";

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 생성자 - MainPage()

    /// <summary>
    /// 생성자
    /// </summary>
    public MainPage()
    {
        InitializeComponent();

        this.createTestFileButton.Clicked += createTestFileButton_Clicked;
        this.shareFileButton.Clicked      += shareFileButton_Clicked;
    }

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Private

    #region 테스트 파일 생성하기 버튼 클릭시 처리하기 - createTestFileButton_Clicked(sender, e)

    /// <summary>
    /// 테스트 파일 생성하기 버튼 클릭시 처리하기
    /// </summary>
    /// <param name="sender">이벤트 발생자</param>
    /// <param name="e">이벤트 인자</param>
    private void createTestFileButton_Clicked(object sender, EventArgs e)
    {
        string filePath1 = Path.Combine(FileSystem.CacheDirectory, this.fileName1);

        File.WriteAllText(filePath1, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

        Thread.Sleep(1000);

        string filePath2 = Path.Combine(FileSystem.CacheDirectory, this.fileName2);

        File.WriteAllText(filePath2, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
    }

    #endregion
    #region 복수 파일 공유하기 버튼 클릭시 처리하기 - shareFileButton_Clicked(sender, e)

    /// <summary>
    /// 복수 파일 공유하기 버튼 클릭시 처리하기
    /// </summary>
    /// <param name="sender">이벤트 발생자</param>
    /// <param name="e">이벤트 인자</param>
    private async void shareFileButton_Clicked(object sender, EventArgs e)
    {
        string filePath1 = Path.Combine(FileSystem.CacheDirectory, this.fileName1);
        string filePath2 = Path.Combine(FileSystem.CacheDirectory, this.fileName2);

        if(!File.Exists(filePath1) || !File.Exists(filePath2))
        {
            await DisplayAlert("INFORMATION", "테스트 파일을 생성해 주시기 바랍니다.", "확인");

            return;
        }

        await Share.Default.RequestAsync
        (
            new ShareMultipleFilesRequest
            {
                Title = "복수 파일 공유",
                Files = new List<ShareFile>
                {
                    new ShareFile(filePath1),
                    new ShareFile(filePath2)
                }
            }
        );
    }

    #endregion
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요