Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Richard MacCutchan5-Oct-23 4:18
mveRichard MacCutchan5-Oct-23 4:18 
AnswerRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
jschell5-Oct-23 5:48
jschell5-Oct-23 5:48 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work5-Oct-23 10:33
Rod at work5-Oct-23 10:33 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
jschell6-Oct-23 7:10
jschell6-Oct-23 7:10 
QuestionBeginner: Return properties from another Class Pin
Member 159530273-Oct-23 23:58
Member 159530273-Oct-23 23:58 
AnswerRe: Beginner: Return properties from another Class Pin
Gerry Schmitz4-Oct-23 4:32
mveGerry Schmitz4-Oct-23 4:32 
AnswerRe: Beginner: Return properties from another Class Pin
Dave Kreskowiak4-Oct-23 5:36
mveDave Kreskowiak4-Oct-23 5:36 
QuestionUsing await/async Correctly Pin
Kevin Marois25-Sep-23 12:30
professionalKevin Marois25-Sep-23 12:30 
I'm a bit confused on something.

I have a Sharepoint class with a DownloadFileAsync method:
using System.IO;
using System.Threading.Tasks;

namespace WpfApp1
{
    internal class Sharepoint
    {
        public async Task DownloadFileAsync(string folderName, string downloadPath = null)
        {
            var url = _clientContext.Web.ServerRelativeUrl + "/Shared%20Documents/" + folderName;
            Folder targetFolder = _clientContext.Web.GetFolderByServerRelativeUrl(url);
            _clientContext.Load(targetFolder.Files);

            await _clientContext.ExecuteQueryAsync();

            foreach (var file in targetFolder.Files)
            {
                FileInformation sharepointFile = Microsoft.SharePoint.Client.File.OpenBinaryDirect(_clientContext, file.ServerRelativeUrl);
                await _clientContext.ExecuteQueryAsync();

                var path = string.IsNullOrEmpty(downloadPath) ? DEFAULT_DIRECTORY : downloadPath;
                path = path + @"\" + file.Name;
                using (FileStream filestream = new FileStream(path, FileMode.Create))
                {
                    sharepointFile.Stream.CopyTo(filestream);
                }
            }
        }
    }
}

It is called from a Repository class
using System.IO;
using System.Threading.Tasks;

namespace WpfApp1
{
    internal class Repository
    {
        string _appPath;
        Sharepoint _sharePoint;

        public Repository()
        {
            _sharePoint = new Sharepoint();
            _appPath = $"{Path.GetTempPath()}RDSPaymentProcessing";

        }

        public async Task<MyData> GETDataAsync()
        {
            var results = new MyData();

            // If the local file already exists, delete it
            var fileName = $"{Path.GetTempPath()}{LOCAL_APP_DATA_FOLDER}\sharepointdata.xml";
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            // Download all files from the Settings folder into the local user's app path
            await _sharePoint.DownloadFile(SETINGS_FOLDER, _appPath);

            // If the file was downloaded...
            if (File.Exists(fileName))
            {
                // Deserialize it
                results = Serialization.DeSerializeObject<MyData>(fileName);
            }
            else
            {
                //TODO: Replace with custom exception
                throw new FileNotFoundException(fileName);
            }

            return results;
        }
    }
}
and that is called from the MainWindowViewModel's loaded method:
namespace WpfApp1
{
    internal class MainWindowViewModel
    {
        private MyEntity _data;

        /// <summary>
        /// Occurs when the window's Loaded event is callled
        /// </summary>
        public async void WindowLoadedExecuted()
        {
            await _repository.GETDataAsync();
        }
    }
}
The question is about where to use await/async? I want to UI to be responsive throughout all of this? Am I coding this right? Or does await/async only need to be on the Sharepoint class?
In theory, theory and practice are the same. But in practice, they never are.”
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.

AnswerRe: Using await/async Correctly Pin
Gerry Schmitz25-Sep-23 16:13
mveGerry Schmitz25-Sep-23 16:13 
GeneralRe: Using await/async Correctly Pin
Kevin Marois25-Sep-23 16:49
professionalKevin Marois25-Sep-23 16:49 
GeneralRe: Using await/async Correctly Pin
Gerry Schmitz25-Sep-23 17:06
mveGerry Schmitz25-Sep-23 17:06 
AnswerRe: Using await/async Correctly Pin
Richard Deeming25-Sep-23 21:52
mveRichard Deeming25-Sep-23 21:52 
QuestionWin Forms, WPF, WinUI 3 Pin
Member 1210196924-Sep-23 10:04
Member 1210196924-Sep-23 10:04 
AnswerRe: Win Forms, WPF, WinUI 3 Pin
Gerry Schmitz24-Sep-23 18:08
mveGerry Schmitz24-Sep-23 18:08 
AnswerRe: Win Forms, WPF, WinUI 3 Pin
#realJSOP19-Mar-24 2:50
mve#realJSOP19-Mar-24 2:50 
Question.NET 4.7 Desktop Form combox coloring within datagridview Pin
.NET4Ever22-Sep-23 4:50
.NET4Ever22-Sep-23 4:50 
AnswerRe: .NET 4.7 Desktop Form combox coloring within datagridview Pin
Alan N22-Sep-23 13:40
Alan N22-Sep-23 13:40 
GeneralRe: .NET 4.7 Desktop Form combox coloring within datagridview Pin
.NET4Ever25-Sep-23 4:02
.NET4Ever25-Sep-23 4:02 
QuestionWhat are Custom Control and User Control? Pin
Emmanuel Katto22-Sep-23 1:31
professionalEmmanuel Katto22-Sep-23 1:31 
AnswerRe: What are Custom Control and User Control? Pin
OriginalGriff22-Sep-23 2:23
mveOriginalGriff22-Sep-23 2:23 
GeneralRe: What are Custom Control and User Control? Pin
Gerry Schmitz22-Sep-23 4:05
mveGerry Schmitz22-Sep-23 4:05 
QuestionFIREBASE Filter Data from Date to Date Pin
sameera suresh bandara herath18-Sep-23 3:04
sameera suresh bandara herath18-Sep-23 3:04 
AnswerRe: FIREBASE Filter Data from Date to Date Pin
OriginalGriff18-Sep-23 4:05
mveOriginalGriff18-Sep-23 4:05 
AnswerRe: FIREBASE Filter Data from Date to Date Pin
Richard Deeming18-Sep-23 4:55
mveRichard Deeming18-Sep-23 4:55 
AnswerRe: FIREBASE Filter Data from Date to Date Pin
jschell18-Sep-23 5:38
jschell18-Sep-23 5:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.