I have a simple win forms application which loads/saves datasets into XML files. As long as I'm working with file shares or the local file system all is good.
Using the standard open file/save file dialog on my Windows 8 box, allows me to browse to my sharepoint using
https:// some sharepoint host
and I can browse the sharepoint sites/projects and document libraries.
Here's the weird part (because I didn't expect it to work like this at all):
When I use the file save dialog to browse to a sharepoint document library, the path is converted into something like '\sharepointhost#SSL\somepath\somemorepath\somefile.xml'
Passing the above path to the DataSet WriteXml method works fine and the file is correctly written to the document library.
Passing the very same path to the DataSet ReadXml method doesn't work and I get an exception:
"Invalid URI: The hostname could not be parsed."
What am I missing here. I mean, I expected both methods to use the same code to parse/resolve the path.
Are you able to check if your code works on non-secured (http) connection? Maybe this error applies to your scenario?
XmlReader for webdav path with ssl (ReadXml internally uses XmlReader).
I guess you might have to add prefix ftp://" or "http://" in your READXML
Related
I am developing an application in asp.net, vs2015 using c# and the development environment is a Win10Pro machine. I can use any of the various methods to obtain the working directory and see if a particular file exists on the dev pc, but not on the Web Server. I have tried the methods laid out on:
Get current application physical path within Application_Start
All work on the Dev PC, but when used on the Web Server it will not return the working directory. The Server is a 2016 Data server using IIS10. The issue is that the web site I am putting together work fine, except to display GrapeCity ActiveReports reports AR15. The web page containing their web viewer opens just fine and is looking for a report file (MyReport.rdlx). The global.aspx file is pointing to the root directory but when the web viewer opens up, it says File Not Found. I have absolutely no idea and tech support is not sure. Is this an IIS issue that is preventing the code to locate and verify the file is there? Any direction would be much appreciated. This has been very frustrating and time consuming.
AppDomain.CurrentDomain.BaseDirectory does not work, HttpRuntime.AppDomainAppPath does not as well as all the others. The request comes back blank.
string filename = AppDomain.CurrentDomain.BaseDirectory.ToString() +"SPU01_Dates.rdlx";
if (File.Exists(filename))
{
Response.Write("YES");
}
else
{
Response.Write("NO");
Response.Write("</br");
Response.Write(filename);
}
All this just returns nothing.
Thanks.
Try this code
if (File.Exists(Server.MapPath(filename)))
Check if a file exists on the server
In my test, it returned YES and worked well. Did you put "SPU01_Dates.rdlx" file in root folder?
In the development environment, it returned YES, and when I deployed it to IIS, it returned NO. I found that during the deployment process, the rdlx file was not deployed with the project, so I recreated one in the deployed folder, and it returned YES.
The test proves that AppDomain.CurrentDomain.BaseDirectory is the most accurate way to get the file path. When you test this code in IIS, does it return NO or empty? Returning empty means that this piece of code has not been executed.
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 am using the WorkSite COM API to open an IMANEXT2Lib.IManFileOpenDlg which is working perfectly. Clicking on the document, I can retrieve the metadata, such as the document name, version, number etc.
Is there a method or technique available to read the document from WorkSite and prompt a download/open through a browser?
The IManage.IManDocument has the method GetCopy() available which will download a local copy to a specified directory, but this isn't really what I'm after.
If the clients have Worksite 8.5 or greater, you can use the IWL protocol in a hyperlink to force the client to use the IWL handler to download and launch the file themselves instead of streaming it from the browser. This has the added benefit of respecting the document's permissions and checking the document out to the user so they can make amends to the file if required.
An IWL formatted anchor tag in a web browser would look like the following:
Document x
Note that this will only work if the clients have Worksite 8.5 or newer installed.
I have a file stored on the server and the web page I am populating depends on the fatc that the file exists or not.
How do I test if the file is available on the server?
The file comes on the web page as:
http://main.server.com/PGT/Reports/ObjectsReport.xml
I have to test the existence of this file and if it is available I will display a link otherwise I want to hide the link.
The actual path to the server is
//main.server.com/inetpub/wwwroot/PGT/Reports/ObjectsReport.xml
but I don't have access to the server (and therefore to the file) on the network. I can only access it using the web page. Is there a way to test that the server has the file or not display the link? (hlObjectsReport.Visible = false;)
I have tried to use the following:
Uri validatedUri;
Uri.TryCreate(uri, UriKind.RelativeOrAbsolute, out validatedUri);
But it returns a valid address even if the file is not there.
Thanks
Tony.
use System.IO.File.Exists() (Documentation)
if(System.IO.File.Exists([path goes here]))
{
// do something
}
If you're not sure of the physical path, you can substitute the following for [path goes here] above:
Server.MapPath(/PGT/Reports/ObjectsReport.xml)
(Documentation)
i have a URL and when i load it up in a browser it recognizes it as a csv file and pops up excel "do you want to open". I want to do this programatically so i can have a winforms app use that url and parse the csv file directly.
what is the quickest way to do this?
EDIT: i tried using WebClient and i am getting the folowing error:
"The remote server returned an error: (500) Internal Server Error."
I don't see why something like this wouldn't work (in C#):
// Download the file to a specified path. Using the WebClient class we can download
// files directly from a provided url, like in this case.
System.Net.WebClient client = new WebClient();
client.DownloadFile(url, csvPath);
Where the url is your site with the csv file and the csvPath is where you want the actual file to go.
If you have a WinForms app, you can use a System.Net.WebClient to read the data as a string.
It will read the entire csv file as a string, but you can write it out or parse it at will.
If you want to just whip something together I would suggest using a scripting language and some bash. Just use wget or something similar to get the file and some scripting language to parse it. You could even use php to parse it once you had the file because I know that php has the following function which is very nice: http://php.net/manual/en/function.fgetcsv.php
I would suggest doing it this way because it is easier, this will certainly let you parse it easily enough though I don't know what you want to do with it from there but the worlds your oyster.
The following code works for me but I am running Open Office. I have not tested it with Excel.
The hacky bit is to rename the local copy of the file to *.xls so that Windows will launch Excel by default, if you leave the file extension as CSV, Windows will launch Notepad by default.
String url = "http://www.example.com/test.csv";
String localfile = "test.xls";
var client = new WebClient();
client.DownloadFile(url, localfile);
System.Diagnostics.Process.Start(localfile);