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;
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:
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.
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";
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);
Permissions: Make sure that the application running on the server has the necessary permissions to access the D drive and the specified directories.
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.
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?
@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.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.