Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying upload a ppt file I am getting expectation like
Could not find a part of the path 


"Could not find a part of the path 'C:\\Projects\\Workplace Select\\ISG.WorkPlaceSelectWeb\\ISG.SelectX\\Content\\Documents\\Service Provider Case Studies_Workplace Select\\Centurylink&Freightliner Dealer&Americas&North America&United States&Travel and Transportation&Transportation&Next-Gen ADM Services&Next-Gen ADM#C1#2020.pptx'."


i doubt that last part of the file name ." causing the problem

the code is
string appPath = WebConfigurationManager.AppSettings["rootPath"].ToString();
              string templatePath = Server.MapPath(appPath + "Service Provider Case Studies_Workplace Select");

var physicalPath = Path.Combine(templatePath, FileName);
                            item.SaveAs(physicalPath);


What I have tried:

Not able to figure out what is the issue

I am able to upload another ppt file with the same code
Posted
Updated 10-Nov-20 22:09pm
v2
Comments
[no name] 11-Nov-20 2:57am    
Maybe try a shorter file name ... and without all the special characters.
murkalkiran 11-Nov-20 3:02am    
Accenture&European Gas & Electricity Supplier&Europe&Energy&Utilities&Next-Gen ADM&Next-Gen ADM&AMS#2020

this file name I can upload without error
Richard MacCutchan 11-Nov-20 4:05am    
Are those double backslash characters actually in the path that you are using?

The filepath is too long. The Microsoft documentation[^] states
Quote:
In editions of Windows before Windows 10 version 1607, the maximum length for a path is MAX_PATH, which is defined as 260 characters. In later versions of Windows, changing a registry key or using the Group Policy tool is required to remove the limit.
Your fully-pathed filename is 286 characters long - regardless of whether you have used spaces, ampersands and underscores.

If you are using Windows 10 or better you can change the registry to get around this limitation - see Maximum Path Length Limitation - Win32 apps | Microsoft Docs[^]

However, consider if your program is going to be run on a user machine where they may not want to, or may not be allowed to, change registry settings.

Using periods (\ISG.SelectX\) and spaces (\Service Provider Case Studies_Workplace Select\) in folder names is not usually considered good practice - it can easily be misunderstood - in the former case it may be mistaken for a file called ISG.SelectX and in the latter you are forcing the user to surround the name with double-quotes if using any cmd instructions, such as DIR

Also consider the impact of having a folder tree 7 layers deep - you might think it's nicely organised but have you gone too far with that concept? You have effectively prevented any migration to a URL based system (such as Sharepoint - not necessarily a bad thing :laugh:). Does it really make things easier to find?

Finally, consider how people will see that file name if they need to select it to open it and view it - the file name is not going to fit in any window and it looks as if the last 4 characters, which they will not be able to see, might actually be important when choosing which file to open. If I was your user I would be rather annoyed.
 
Share this answer
 
If the code can upload some files, then check the exact path it provides and ensure that every part of it is available.
Open a browser on the server and paste the full path into the address bar: what does it say? Try the same thing using Windows explorer on the server, without the file name.
If it opens the file, it's probably a permissions problem. Websites don't run under your user ID, so unless the full path is available to all users, you probably can't reach it from C#.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900