Issue with gridJsWorkbook.ImportExcelFile - Path Not Found Error on Server

I am encountering an issue with the gridJsWorkbook.ImportExcelFile method when running on a server that only has a C drive. The following error is thrown:

System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath): Could not find a part of the path ‘D:\tmpdel\storage\piccache\0446aea0-017d-49ba-97b6-af4f0cefd91b.xlsx’.

The code works fine on my local machine, where both C and D drives are available. please find my full code.

public static StringBuilder ExcelReaderFromPath(string filePath, string licPath)
{
// Config.set_FileCacheDirectory(“C:\tmpdel”);

  Config.FileCacheDirectory = @"C:\\tmpdel";
  if (!Directory.Exists(Config.FileCacheDirectory))
      Directory.CreateDirectory(Config.FileCacheDirectory);
  Viewer.setLicence(licPath);
  GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
  string uidForFile = GridJsWorkbook.GetUidForFile(filePath);
  StringBuilder stringBuilder = gridJsWorkbook.GetJsonByUid(uidForFile, filePath);
  if (stringBuilder == null)
  {
      Workbook workbook = new Workbook(filePath);
      using (IEnumerator<Worksheet> enumerator = ((CollectionBase<Worksheet>)workbook.Worksheets).GetEnumerator())
      {
          while (((IEnumerator)enumerator).MoveNext())
              enumerator.Current.RemoveAutoFilter();
      }
     gridJsWorkbook.ImportExcelFile(uidForFile, filePath, "");
      
     string jsonfile = gridJsWorkbook.ExportToJson(filePath);
     stringBuilder = gridJsWorkbook.ExportToJsonStringBuilder(filePath);
  }
  return stringBuilder;

}

@parthiveera

The error you are encountering, which states that a part of the path could not be found, typically occurs when the specified directory or file does not exist on the server. Since your server only has a D drive, you need to ensure that all paths used in your code are valid and accessible on that drive.

Here are a few steps you can take to resolve the issue:

  1. Check File Path: Ensure that the file path you are passing to the ImportExcelFile method is correct and that the file actually exists at that location on the D drive. You can add some debugging code to verify the file path before attempting to import it.

  2. Set Cache Directory: In your code, you are setting the cache directory to C:\tmpdel, which may not exist on your server. Since your server only has a D drive, you should change this line:

    Config.FileCacheDirectory = @"C:\\tmpdel";
    

    to a valid path on the D drive, for example:

    Config.FileCacheDirectory = @"D:\\tmpdel";
    
  3. Create Directory: Ensure that the directory you are setting as the cache directory exists. You can create it programmatically if it does not exist:

    if (!Directory.Exists(Config.FileCacheDirectory))
        Directory.CreateDirectory(Config.FileCacheDirectory);
    
  4. Permissions: Make sure that the application running on the server has the necessary permissions to access the D drive and the specified directories.

  5. Debugging: You can add logging to check the values of filePath and Config.FileCacheDirectory before they are used, which can help identify any discrepancies.

Here is a modified version of your code snippet with the cache directory set to the D drive:

public static StringBuilder ExcelReaderFromPath(string filePath, string licPath)
{
    Config.FileCacheDirectory = @"D:\\tmpdel"; // Updated to D drive
    if (!Directory.Exists(Config.FileCacheDirectory))
        Directory.CreateDirectory(Config.FileCacheDirectory);
    
    Viewer.setLicence(licPath);
    GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
    string uidForFile = GridJsWorkbook.GetUidForFile(filePath);
    StringBuilder stringBuilder = gridJsWorkbook.GetJsonByUid(uidForFile, filePath);
    
    if (stringBuilder == null)
    {
        Workbook workbook = new Workbook(filePath);
        using (IEnumerator<Worksheet> enumerator = ((CollectionBase<Worksheet>)workbook.Worksheets).GetEnumerator())
        {
            while (((IEnumerator)enumerator).MoveNext())
                enumerator.Current.RemoveAutoFilter();
        }
        gridJsWorkbook.ImportExcelFile(uidForFile, filePath, "");
        
        string jsonfile = gridJsWorkbook.ExportToJson(filePath);
        stringBuilder = gridJsWorkbook.ExportToJsonStringBuilder(filePath);
    }
    return stringBuilder;
}

By ensuring that all paths are valid and accessible on the server, you should be able to resolve the path not found error.

I am encountering an issue with the gridJsWorkbook.ImportExcelFile method when running on a server that only has a C drive.

@parthiveera,

Apparently this is System.IO error. If your server only has C drive, you have to use or set all valid (file) paths on C drive only. Please make sure that the application running on the server has the necessary (read and write) permissions to access the C drive and the specified directories. What are the values you are giving for filePath, licPath and FileCacheDirectory attributes?

I have given full rights to the folder C:\tmpdel.

  • Filepath: \\Chninsusanweb01\cmrplus\Prediction\7_10_SOV\SOV\241209154544737_143\Display\30_24-25 Property Schedule (sub).xlsx
  • Licpath: C:\Projects\github\Insurant\Insurant_CMRWeb\ANT.Build\Modules\Aspose.Total.NET.lic

Previously, I only set:
Config.FileCacheDirectory = @"C:\\tmpdel";

What do you mean by the FileCacheDirectory attribute?

@parthiveera,

I meant value of the property, which looks OK as you provided.

We might need to setup a machine where only D drive is available. Let us evaluate your issue in details and then we will get back to you with updates.

@parthiveera
What is the version do you use?
please check the document here

if you use GridJsWorkbook.CacheImp
You can debug here

GridJsWorkbook.CacheImp=new LocalFileCache();
public class LocalFileCache  : GridCacheForStream
    {
         
        /// <summary>
        /// Implement this method to savecache,save the stream to the cache object with the key id.
        /// </summary>
        /// <param name="s">the source stream </param>
        /// <param name="uid">the key id.</param>
        public override void SaveStream(Stream s, String uid)
        {
        //make sure the directory exist,
String filepath = Path.Combine(Config.FileCacheDirectory, uid);
// You can change it according to your environment.