New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SaveFileService & OpenFileService should support Windows file filters in UWP #1123

Closed
byrialsen opened this Issue Sep 27, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@byrialsen

byrialsen commented Sep 27, 2017

Steps to reproduce

Call: _saveFileService.DetermineFileAsync() in a UWP project.

Platform:
UWP 14393 (Anniversary Update)

Actual behaviour

An exception is raised.

To my investigation it seems like that UWP Control FileSavePicker should have set at least one FileTypeChoices to work. Like this code:

 FileSavePicker savePicker = new FileSavePicker();
 savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });

Maybe OpenFileService has similar problems?

@GeertvanHorrik

This comment has been minimized.

Show comment
Hide comment
@GeertvanHorrik

GeertvanHorrik Sep 29, 2017

Member

Yes, OpenFileService will probably have the same issues. Thanks for reporting, we'll put it on the release vNext.

Member

GeertvanHorrik commented Sep 29, 2017

Yes, OpenFileService will probably have the same issues. Thanks for reporting, we'll put it on the release vNext.

@GeertvanHorrik GeertvanHorrik added this to the 5.2.0 milestone Sep 29, 2017

@GeertvanHorrik

This comment has been minimized.

Show comment
Hide comment
@GeertvanHorrik

GeertvanHorrik Sep 29, 2017

Member

Can you please create a small repro so we can easily test the fixes?

Member

GeertvanHorrik commented Sep 29, 2017

Can you please create a small repro so we can easily test the fixes?

@byrialsen

This comment has been minimized.

Show comment
Hide comment
@byrialsen

byrialsen Sep 29, 2017

Sounds good, and offcourse I will do that. I will try to do it during this weekend.

And let me also say. As this is a very well written piece of framework it was easy to override the DetermineFileAsync to temporary handle the problem

public async override Task<StorageFile> DetermineFileAsync()
{
  // init
  var saveFileDialog = new FileSavePicker();
  saveFileDialog.SuggestedFileName = FileName;

  // handle FileTypeChoices from Filters like "Log files|*.txt"
  try
  {
     string[] filterParts = Filter.Split(new char[] { '|' }, 2);
     if (filterParts.Length == 2)
     {
       List<string> extensions = new List<string>();
       foreach (string extension in filterParts[1].Split(new char[] { '|' }))
       {
         extensions.Add(extension.TrimStart(new char[] { '*', ' ' }));
       }

       saveFileDialog.FileTypeChoices.Add(filterParts[0], extensions);
     }
  }
  catch (Exception ex)
  {
    log.Debug(ex);
   }
}

byrialsen commented Sep 29, 2017

Sounds good, and offcourse I will do that. I will try to do it during this weekend.

And let me also say. As this is a very well written piece of framework it was easy to override the DetermineFileAsync to temporary handle the problem

public async override Task<StorageFile> DetermineFileAsync()
{
  // init
  var saveFileDialog = new FileSavePicker();
  saveFileDialog.SuggestedFileName = FileName;

  // handle FileTypeChoices from Filters like "Log files|*.txt"
  try
  {
     string[] filterParts = Filter.Split(new char[] { '|' }, 2);
     if (filterParts.Length == 2)
     {
       List<string> extensions = new List<string>();
       foreach (string extension in filterParts[1].Split(new char[] { '|' }))
       {
         extensions.Add(extension.TrimStart(new char[] { '*', ' ' }));
       }

       saveFileDialog.FileTypeChoices.Add(filterParts[0], extensions);
     }
  }
  catch (Exception ex)
  {
    log.Debug(ex);
   }
}
@byrialsen

This comment has been minimized.

Show comment
Hide comment
@byrialsen

byrialsen Sep 30, 2017

Hope this small sample will help you testing a fix:

SaveAndOpenFileService.zip

byrialsen commented Sep 30, 2017

Hope this small sample will help you testing a fix:

SaveAndOpenFileService.zip

@GeertvanHorrik GeertvanHorrik modified the milestones: 5.2.0, 5.3.0 Oct 5, 2017

@GeertvanHorrik GeertvanHorrik modified the milestones: 5.3.0, 5.4.0 Jan 19, 2018

@GeertvanHorrik GeertvanHorrik self-assigned this Mar 26, 2018

@GeertvanHorrik GeertvanHorrik modified the milestones: 5.4.0, 5.5.0 Apr 16, 2018

@GeertvanHorrik GeertvanHorrik changed the title from SaveFileService in UWP is broken to SaveFileService & OpenFileService don't support Windows file filters in UWP May 16, 2018

@GeertvanHorrik GeertvanHorrik changed the title from SaveFileService & OpenFileService don't support Windows file filters in UWP to SaveFileService & OpenFileService should support Windows file filters in UWP May 16, 2018

@GeertvanHorrik

This comment has been minimized.

Show comment
Hide comment
@GeertvanHorrik

GeertvanHorrik May 16, 2018

Member

The issue was the services need a different way of passing in file filters. We've made the service compatible with full Windows file filters, they will now automatically be converted to UWP file filters.

Member

GeertvanHorrik commented May 16, 2018

The issue was the services need a different way of passing in file filters. We've made the service compatible with full Windows file filters, they will now automatically be converted to UWP file filters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment