I have files with filename containing # in it (eg: #qwerty.txt, file#1.exe).
I want to upload these files to WebDAV Server, running on Linux.
In ASP.Net, I use HttpUtility.UrlEncode() Method for encoding URL.
But, this removes # from the file-names, to be uploaded and thus uploading fails.
Please reply.
Thanks.
UrlEncode does not remove pound/hash characters but replaces them by %23.
Thus #qwerty.txt becomes %23qwerty.txt. If you use that resulting filename to reference the local file for uploading it will fail to find it.
If you want a more definitive answer you might want to update your question with the code you are using to upload the file.
Related
I am looking for a way to derive the OneDrive file URL for a file cached to my local OneDrive folder? The only thing I can think of is hardcoding some root URLS for each of the OneDrive folders I have, but this seems nasty!
Does anyone know of any OneDrive client API that lets query a URL based on the local file path?
My use case:
I am trying to attach to and open instance of an Excel workbook. I used to be able to do this Marshal.BindToMoniker(_workbookPath);
However it appears that Excel is now registering the OneDrive URL in the ROT rather than the local file path. This this happened with the update that brought the new auto-save feature to Excel 2016 I think, that seems to be about the time my existing code broke.
There is a similar unanswered question here: C# OneDrive for Business / SharePoint: get server path from locally synced file
Might want to use the following key instead:
HKEY_CURRENT_USER\Software\SyncEngines\Providers\OneDrive
This includes the following registry values:
UrlNamespace: (SharePoint site URL)
MountPoint: (local driver location)
It does appear to include old values which are no longer synced - but it shouldn't be too hard to check against
HKEY_CURRENT_USER\Software\Microsoft\OneDrive\Accounts\Business1\ScopeIdToMountPointPathCache
or
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SyncRootManager
for paths that are being actively synced.
I am also looking at a solution for getting the SharePoint url to a file in OneDrive Synced File Explorer.
I have noticed you get under C:\Users%username%\AppData\Local\Microsoft\OneDrive\settings\Business1{GUID}.ini a mapping between your OneDrive synced folder and the SharePoint GUID
Example:
libraryScope = 1 630c2a866d9c458b81060eff107887ed+1 5 "GUIDEs" "Documents" 4 "https://mytenant.sharepoint.com/teams/team_10000035" "8d4b558f-7b2e-40ba-ad1f-e04d79e6265a" e0266a43caf347238f684bab486f4e51 e0d25dcb1a014f5f86d787984f6327c2 4f86b3e3e54e42e0bb0f7a58eadf0335 0 "" 0 4cde5c00-3fe3-4162-b831-d8ef440e1593 libraryFolder = 0 1 8bbfe07dfeff41cea7ab5da4a554592a+1 1558084235 "D:\DSUsers\uid41890\TenantName\GUIDEs - General" 2 "General" bd0c1b7c-2a1f-4492-8b1b-8e152c9e0c26
You also have this mapping in the registry Computer\HKEY_CURRENT_USER\Software\Microsoft\OneDrive\Accounts\Business1\ScopeIdToMountPointPathCache
From the GUID you could get the path using SPWeb.GetFile(Guid)
If you can make a standalone function given a local OneDrive file path that returns the SharePoint url, I would greatly appreciate you share your solution here.
I have implemented a solution in AutoHotkey see documentation here
It is based on #GWD idea (see comments below) to generate a temporary excel file with the formula CELL("filename") at each sync locations to extract this mapping information to a text file that is then later parsed to do the reverse mapping from local file to SharePoint url.
I have a problem in my MVC 3 Application
i can't access to my image with url like that:
http://virtualDirectoryImage.fr/ImageNameContains+.jpg
or
http://virtualDirectoryImage.fr/ImageNameContains%2b.jpg
I got Error 404 file not found (the file exist, i can access to others images witch dont contains plus (+) symbol).
How can i do plz?
IIS7 issue? Application issue?
PS: the images are not hosted in my application. (Virtual Directory, on the same Server)
thx for your help
Can you follow the steps given in the following url
http://helpx.adobe.com/cq/kb/CannotOpenAFileHavingSpecialCharactersInTheFilenameOnIIS.html
basically IIS will block the file names if it contains any special characters.Esspecially if it contains & in the file name for security reasons.It's a good practice to replace the special characters with "_" while uploading the file to the server
I'm using FileUpload.SaveAs() function of C# to upload files to the server but I want to save the files on another partition. Let us say, save the files on Drive D of the server instead on the current drive which is Drive C. Please share your thoughts. Thanks is advance.
I have learned that using full path such as
FileUpload.SaveAs("D:\FileUpload");
will save the file outside the web server.
Check this out.
To simplify the question, how can I upload files on the other partition of the server that hosts my web app?
Based on the documentation from http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.saveas.aspx, the String filename is the full path name of the location to save. Meaning you should be able to do so e.g:
FileUpload.SaveAs("D:\where_you_want_to_save")
By the way what have you tried and what error did you get?
Looking at the example on MSDN, it would appear that .SaveAs() accepts a fully qualified file name as a parameter. You could potentially use a Path object to cleanly build a path for the file, or just specify one directly as a string:
uploader.SaveAs("d:\\someFolder\\someFile.ext");
Resolved this by using Virtual Directory of IIS and providing admin credentials for authentication
File.Exists is returning false when the file actually exists.
I know it would return false if there's no read permissions, but I can't seem to get it right.
More info:
My FTP directory is organized like so:
Root
ImageSite
ImageDirectory
MySite
My .aspx.cs File that's calling File.Exists()
I tried uploading the .aspx.cs file with the same ftp user account as ImageSite & ImageDirectory. Didn't help.
I also tried replacing forward slashes with back slashes, just to be sure.
Here's my code - I hard-coded the file path to the complete ftp path of the image directory.
string serverUrl =#"\\fs4-n01\blah\blah\blah\ImageSite.com\web\content\Images\" + product.ImageUrl;
bool exists = File.Exists(serverUrl);
I also thought of impersonation. I am already using one identity impersonation in my web.config and it didn't seem to let me use both, so I placed this one under the subdirectory where my code file is, under tag. But it didn't seem to do it. (Either way, the owner of the file is the same as the image directory, as I mentioned.)
I'm using ASP.NET 4.0.
Any ideas would be appreciated.
I called my hosting provider (Rackspace) and was told the way .NET works is you cannot access files beyond the content directory for security reasons. (For ASP classic sites, it does let you, as of now.)
I have a problem with my code. My code is using the fileupload control to browse for a filename when you add a filename it processes it and the code runs fine on when it lives on local host, but when I put the code on our prodution server it cannot find the filenames listed by user.
For example if I use the upload control to browse to
B:\MIS\CH Intive\RPTTOFL_3.csv and the code lives on my localhost which know what that file path means it works, but if the code is moved to a production server it may or maynot know what B:/ is or B:/ maybe mapped to something else.
Even if I am browsing to a file on my C drive it will work on if the code is on the machine that the C drive is on, but it will not work if the code is on another machine because obviously that file wouldnt be on that C drive.
Private Function CSV2DataTable(ByVal filename As String) As DataTable
Using MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser(filename)
MyReader.TextFieldType = FileIO.FieldType.Delimited
.
.
.
What can I do in asp.net to make the filename work correctly?
Ok lets say I get the filename and save it as so
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
now I want to pass the filename to the function above for processing. Do I pass Server.MapPath("~/") + filename as the filename? Also when I am done what do I do to delete the file from the server?
It seems that you are mixing the client and server locations of the file. Before reading the uploaded file, the server-side code must save it on the server (client-side file location is mostly irrelevant at this point). From VS help on FileUpload class: "The code that you write to save the specified file should call the SaveAs method, which saves the contents of a file to a specified path on the server." The online help topic on FileUpload control has enough information (with examples) to achieve what you need.