Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am developing a simple WPF Image viewer using c#. I am adding a feature so you can right-click on the image to open the file path. I am using Process.Start to open explorer with the path as the arguments. My app runs fine but won't open explorer.

My c# code is

        string selectedFileName;
        string directoryPath;

        private void MenuItemFromFile_OnClick(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Image Files (*.jpg|*.jpg|*.gif|*.ico|*.bmp|*.png|*.wdp| .tiff)|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 8;


            
            if (openFileDialog.ShowDialog() == true)
            {
                selectedFileName = openFileDialog.FileName;
                directoryPath = System.IO.Path.GetDirectoryName(openFileDialog.FileName);
                
                BitmapImage bitmap = new BitmapImage();  
                bitmap.BeginInit();
                bitmap.UriSource = new Uri(selectedFileName);  
                bitmap.EndInit();
                FullImage.Source = bitmap;
            }
        }

        private void ContextItemFileLocation_OnClick(object sender, RoutedEventArgs e)
        {

            Process.Start("C:\Windows\explorer.exe", @directoryPath);
        }

My XAML

        <Image Grid.Row="2" 
               Grid.Column="1" 
               Name = "FullImage" 
               Stretch="Uniform" 
               StretchDirection="Both" >
            <Image.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="open file location" 
                              Name="ContextItemFileLocation" 
                              Click="ContextItemFileLocation_OnClick"/>
                </ContextMenu>
            </Image.ContextMenu>
            
        </Image>
question from:https://stackoverflow.com/questions/65661633/process-start-opening-explorer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
227 views
Welcome To Ask or Share your Answers For Others

1 Answer

I restarted my computer and it seems to be working now. Thanks for the help anyway


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...