I can not upload file to network shared folder

4 Answers 42 Views
FileExplorer
Dongwei
Top achievements
Rank 1
Dongwei asked on 03 Oct 2024, 09:26 PM | edited on 03 Oct 2024, 09:27 PM

I try to use

         <telerik:RadFileExplorer ID="RadFileExplorer1" Runat="server" EnableEmbeddedSkins="True"
             InitialPath="\\network\EL00394132">
             <Configuration ViewPaths="\\network\EL00394132" 
                 DeletePaths="\\network\EL00394132" 
                 UploadPaths="\\network\EL00394132" SearchPatterns="*.*"/>
        </telerik:RadFileExplorer>

 

access a network shared folder by creating my own FileBrowserContentProvider 

            this.RadFileExplorer1.Configuration.ContentProviderTypeName = typeof(Extensions.NetworkShareProvider).AssemblyQualifiedName;

It can view files

 

But when I try to upload a file

 

After click Upload button, it triggers my own FileBrowserContentProvider class

but no files are being uploaded, then get an error

 

it dose not trigger

 

How to fix? Please help !

4 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 04 Oct 2024, 09:16 AM

Hi Dongwei,

The issue you're encountering with file uploads in RadFileExplorer, when using a network shared folder, likely relates to permission and path handling in your custom FileBrowserContentProvider. Here are a few troubleshooting steps and suggestions to address the problem:

  • Check Network Permissions:
    Ensure that the application has proper write permissions to the network share. The CheckWritePermissions method you've implemented always returns true, which means you are bypassing the actual permission check. However, this may hide potential permission issues.
    Try this instead:
    public override bool CheckWritePermissions(string folderPath)
    {
        try
        {
            string testFile = Path.Combine(folderPath, "test.txt");
            using (FileStream fs = File.Create(testFile, 1, FileOptions.DeleteOnClose))
            {
                return true;
            }
        }
        catch
        {
            return false;
        }
    }        
    Make sure the user account under which the web application is running has both read and write permissions on the network share.
  • Path Issues in GetFile Method:
    In your GetFile method, you're combining the url using Path.Combine. If the url is a full UNC path (i.e., \\network\...), then combining it with other parts might cause issues, leading to incorrect paths.
    Instead of Path.Combine, try using the url directly:

    public override Stream GetFile(string url)
    {
        return new FileStream(url, FileMode.Open, FileAccess.Read);
    }
                
  • Check the Upload Process:
    The upload process may not be completing successfully, or the file path may not be handled correctly. In your StoreFile method, the SaveAs operation could be failing silently if the path is not valid. Here are a few things to check:
    • Ensure that the full path being generated is correct. You can add logging to see what fullPath is being generated:
      `
      public override string StoreFile(UploadedFile file, string path, string name, params string[] arguments)
      {
          string fullPath = Path.Combine(path, name);
          // Log fullPath or debug here
          file.SaveAs(fullPath);
          return fullPath;
      }
    • Make sure the file.SaveAs(fullPath) is not silently failing. You can wrap it in a try-catch block to handle and log any exceptions.
  • IIS Configuration:
    If you're hosting this application on IIS, make sure that:
    • The application pool identity has the necessary permissions on the network share.
    • The file size limits in IIS are not preventing the upload (check the maxAllowedContentLength and maxRequestLength settings in the web.config).
  • Test the Sample PhysicalpathFilesystemProvider Application:
    I recommend testing the sample PhysicalpathFilesystemProvider application provided in the following KB article: FileExplorer-PhysicalpathFilesystemProvider.zip.
    It is important to examine how the path mappings are done inside the App_Code\MappingFile.mapping file:

    <?xml version="1.0" encoding="utf-8" ?>
    <CustomFileBrowserProvider>
      <Paths>
        <genericHandlerPath>FileSystemHandler.ashx</genericHandlerPath>
      </Paths>
      <Mappings>
        <Mapping>
          <PhysicalPath>
            <![CDATA[C:\PhysicalSource\ROOT]]>
          </PhysicalPath>
          <VirtualPath><![CDATA[MyCusomRootDir 1/]]></VirtualPath>
        </Mapping>
        <Mapping>
          <PhysicalPath>
            <![CDATA[\\Telerik.com\Path\SharedDir]]>
          </PhysicalPath>
          <VirtualPath><![CDATA[MySharedRootDir/]]></VirtualPath>
        </Mapping>
    
      </Mappings>
    </CustomFileBrowserProvider>

    Regards,
    Rumen
    Progress Telerik

    Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Dongwei
Top achievements
Rank 1
commented on 04 Oct 2024, 04:57 PM | edited

Hi Rumen, 

Thanks for your help!

1. I checked, I do have write permission:

2. I checked web.config, I do have maxAllowedContentLength  and maxRequestLength settings. if I switch to virtual folder with default provider, upload files works fine.

 

3. After I click the upload button in the upload file popup. Should I expect a "saving file" event to be triggered, likely using the StoreFile() method, however, it is never being triggered, but the GetFile() method is being called.

4. How to run and debug your sample code PhysicalpathFilesystemProvider?

Thank you for your time and assistance

0
Rumen
Telerik team
answered on 07 Oct 2024, 06:44 AM

Hi Dongwei,

Thank you for the additional information!

Permissions and Web.config Settings

  • It's good to hear that you have confirmed the write permissions and the necessary web.config settings. Since the upload works with the default provider in a virtual folder, the issue might be related to the custom FileBrowserContentProvider.

Upload Button and StoreFile Method

  • After clicking the upload button, the StoreFile() method should be triggered to handle the file saving process. If StoreFile() is not being called and GetFile() is being called instead, it suggests that the upload process might not be reaching the storage phase correctly.

Debugging the Custom Provider

  • Ensure that the custom provider is correctly set up and that all necessary methods are overridden. Here is a quick checklist and a code snippet to verify your setup:
public class CustomFileBrowserContentProvider : FileBrowserContentProvider
{
    // Constructor
    public CustomFileBrowserContentProvider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths)
        : base(context, searchPatterns, viewPaths, uploadPaths, deletePaths) { }

    public override string StoreFile(UploadedFile file, string path, string name, params string[] arguments)
    {
        string fullPath = Path.Combine(path, name);
        file.SaveAs(fullPath);
        return fullPath;
    }

    public override Stream GetFile(string url)
    {
        return new FileStream(url, FileMode.Open, FileAccess.Read);
    }
    
    // Other necessary overrides...
}

Running and Debugging PhysicalpathFilesystemProvider

To run and debug the PhysicalpathFilesystemProvider sample code, follow these steps:

  • Download and Extract:

    • Download the sample code from the provided link and extract it to your local machine.
  • Open in Visual Studio:

    • Open the solution file (.sln) in Visual Studio.
  • Set Up IIS or IIS Express:

    • Ensure that the project is configured to use IIS or IIS Express with the correct application pool identity having the necessary permissions to access the network share.
  • Configure Paths:

    • Update the MappingFile.mapping file with the correct paths to your network share and ensure the paths are correctly mapped.
  • Debugging:

    • Set breakpoints in the custom provider's methods (e.g., StoreFile, GetFile) and run the project in debug mode.
    • Perform the upload operation and check if the breakpoints are hit, allowing you to step through the code and identify any issues.

Here is a sample MappingFile.mapping configuration:

<?xml version="1.0" encoding="utf-8" ?>
<CustomFileBrowserProvider>
  <Paths>
    <genericHandlerPath>FileSystemHandler.ashx</genericHandlerPath>
  </Paths>
  <Mappings>
    <Mapping>
      <PhysicalPath><![CDATA[\\network\EL00394132]]></PhysicalPath>
      <VirtualPath><![CDATA[MySharedRootDir/]]></VirtualPath>
    </Mapping>
  </Mappings>
</CustomFileBrowserProvider>

Ensure that the paths are correctly mapped and accessible by the application.

If you continue to experience issues, please provide more details or any specific error messages you encounter during debugging.

Please refer to the following articles for additional information:

Regards,
Rumen
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Dongwei
Top achievements
Rank 1
commented on 07 Oct 2024, 05:26 PM

It works now. It dose actually call GetFile() first then call StoreFile()
Dongwei
Top achievements
Rank 1
commented on 07 Oct 2024, 05:39 PM

one more thing. the layout in the upload pop appears to be incorrect.  how to fix?

I set my RadFileExploer use EnableEmbeddedSkins

<telerik:RadFileExplorer ID="RadFileExplorer1" Runat="server" EnableEmbeddedSkins="True" width="100%" FileExplorerMode="FileSystem">

 

 

0
Rumen
Telerik team
answered on 08 Oct 2024, 06:17 AM

I am glad that the FileBrowserContentProvider issue is resolved! 

To address the layout issues in the upload popup, please consider the following steps:

  1. RenderMode="Lightweight" - the Classic rendering is obsolete since 2015 and it is a good idea to switch to Lightweight, which could resolve the issue.

  2. Check for Conflicting Styles: Ensure that there are no conflicting styles in your application that might be affecting the layout of the upload popup. You can inspect the applied styles to the dialog via the browser DevTools Style Inspector. See this blog post for more information: See the Applied Styles.

  3. Custom CSS Adjustments: If the embedded classic skins are not rendering correctly, you might need to add custom CSS to adjust the layout. You can do this by overriding specific CSS classes used by the dialog and import them through the DialogsCssFile property.

    Best Regards,
    Rumen
    Progress Telerik

    Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
    Dongwei
    Top achievements
    Rank 1
    commented on 10 Oct 2024, 06:28 PM | edited

    I changed to 

    <telerik:RadFileExplorer ID="RadFileExplorer1" EnableEmbeddedSkins="true" EnableEmbeddedBaseStylesheet="true" Runat="server" width="100%" RenderMode="Lightweight">
    </telerik:RadFileExplorer>

    but the upload pop up still appears not quite right. How to adjust? 

    Vasko
    Telerik team
    commented on 15 Oct 2024, 12:16 PM

    Hi Dongwei,

    You can adjust the upload popup window with CSS, by targeting its respective classes: 

    .rfeUploadInfoPanel {
        width: 200px;
    }
    
    html body .RadWindow .rwContent {
        background-color: red;
    }


    To narrow down the issue, I would suggest inspecting the HTML elements and the styles applied to them. You can follow the suggestions in the first two points of the Improve Your Debugging Skills with Chrome DevTools blog post explaining how to inspect the generated HTML and check the applied styles for various elements. 

    Once you know the styles you need to override, you can use the same style selector and add "html body " in front of it to make it more specific, and "stronger". More on CSS specificity you can find here: 

    To learn more about CSS styling and using the Browser's developer tools, you may find the following videos useful: 

    Best Regards,
    Vasko
    Progress Telerik

    Dongwei
    Top achievements
    Rank 1
    commented on 21 Nov 2024, 05:06 PM | edited

    Thank you it works
    Dongwei
    Top achievements
    Rank 1
    commented on 21 Nov 2024, 05:23 PM | edited

    How to make this "Drop Files Here" zone bigger?

     

    and when I try to open a file

    I'd like to be able to click on a link to an Excel file and have it open directly in Excel on my computer, without any intermediate popup windows. Is this possible? or download to local?

    0
    Rumen
    Telerik team
    answered on 22 Nov 2024, 09:01 AM

    Hi Dongwei,

    Let's keep discussions centered on the original topic. For any new requests, please create dedicated new forum posts to address them appropriately:

    Regards,
    Rumen
    Progress Telerik

    Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
    Tags
    FileExplorer
    Asked by
    Dongwei
    Top achievements
    Rank 1
    Answers by
    Rumen
    Telerik team
    Share this question
    or