2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PowerAppsで添付ファイルの数と拡張子を制限する

Last updated at Posted at 2021-02-02

概要

  • 以下のようなサムネイルを使ったアプリを作成する場合、保存場所はSharePointの添付ファイルフィールドを使い、画像のアップロードは編集フォームで添付ファイルコントロールを利用する方法が簡単です。
  • ただし添付ファイルコントロールで「画像は1つまで」、「登録できるのは画像のみ」といった制約をつけるには少し工夫が必要です。
    image.png

※SharePointリストをデータソースとする場合を想定。

①画像を1つしか添付できないようにする

添付ファイルコントロールにはMaxAttachmentsプロパティがあり、添付できるファイル数を制限できます。
普通にMaxAttachmentsを1にすると既にファイルがある場合は入れ替えができなくなるため、以下のような工夫が必要です。

画面の設定
・OnVisible:UpdateContext({MaxFileCount:1})

添付ファイルコントロールの設定
image.png
image.png
既存のファイルを削除したときは2、それ以外は1が設定されるようにします。

②添付できるファイルの種類を制限する

ラベルコントロールを追加し、Textプロパティに以下のような関数を設定。
CountIf関数で指定のパターンに一致しないファイルの数をカウントします。

Label_DeniedFileCount.Text
CountIf(DataCardValue_添付ファイル.Attachments,!IsMatch(ThisRecord.Name,".(gif|jpg|png|bmp|webp)",IgnoreCase & EndsWith))

次に、サブミットボタンで添付できないファイル数をチェックして登録を制限します。

Icon_Submit.OnSelect
If(Value(Label_DeniedFileCount.Text) > 0,
    Notify("添付できないファイルがあります",NotificationType.Error),
    SubmitForm(Form_RegisterFood)
)

image.png

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?