pptm file not downloading on IIS 6.0 - c#

I have uploaded a .pptm file on windows 2003 server in a website directory folder. I get a link to the file like www.domainname/media/CLT/ResourceUploads/4021161/proposal%20sample.pptm when I type in the link in the browser address bar I get this error
Gateway Timeout Server error - server xx.xxx.xxxx.176 is unreachable at this moment. Please retry the request or contact your adminstrator.
If I change the extension of the same file to .ppt or .pptx then the document downloads fine.
I have also tried a different sample file (available on this link http://greenvsa.wikispaces.com/file/detail/proposal+sample.pptm) but the result is still the same.
Any ideas or any direction I shall look into? thanks

Related

Application can find 'Downloads' folder when debugging but not on IIS

I have an application that allows the user to upload a file (saving it to in a folder located in the wwwroot of the ASPNETCORE application). From here they can make edits to it and then they can choose to export the file as a csv/ xml/ xlsx which downloads the file to the user's 'downloads' folder.
While debugging in Visual Studio this all works fine however when I publish and deploy the application to IIS I am getting the exception
Error saving file C:\windows\system32\config\systemprofile\Downloads(FILE NAME)
Could not find part of the path C:\windows\system32\config\systemprofile\Downloads(FILE NAME)
This is the current way I am getting the downloads folder:
FileInfo file = new FileInfo(Path.Combine(Environment.ExpandEnvironmentVariables(#"%USERPROFILE%\Downloads"), data.Filename + "." + data.FileType));
However I have also tried the solution that Hans Passant has answered to a similar question here. Both solutions worjk fine while debugging locally however as soon as I publish them, this one produces the exception:
Value cannot be null. Parameter name: path1
Which I presume is thrown at this point here when I try and save the file to the user's download folder.
using (var package = new ExcelPackage(file))
{
var workSheet = package.Workbook.Worksheets.Add("ExportSheet");
workSheet.Cells.LoadFromCollection(exports, true);
package.Save();
}
I don't really know how I would be able to reproduce these exceptions seeing as locally using Visual Studio it all works fine.
Has anyone else came across this issue while trying to download a file?
UPDATE: When the application is running on IIS, it seems to be using that as the user profile instead of the actually user, so when it tries to navigate to the Downloads folder, it cannot find it. How can I force it to use the user's profile?
LoadUserProfile is already set to True.
Web applications have no knowledge of the end-user's computer's filesystem!
So using Environment.GetFolderPath or Environment.ExpandEnvironmentVariables in server side code will only reveal the server-side user (i.e. the Windows Service Identity)'s profile directories which is completely separate and distinct from your web-application's actual browser-based users OS user profile.
As a simple thought-experiment: consider a user running a weird alien web-browser on an even more alien operating system (say, iBrowse for the Amiga!) - the concept of a Windows-shell "Downloads" directory just doesn't exist, and yet here they are, browsing your website. What do you expect your code would do in this situation?
To "download" a file to a user, your server-side web-application should serve the raw bytes of the generated file (e.g. using HttpResponse.TransmitFile) with the Content-Disposition: header to provide a hint to the user's browser that they should save the file rather than try to open it in the browser.

Get onedrive file URL from a the locally cached file

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.

Upload File from Client to Server C#

Got an issue "Path Not Found" when try to upload an image from Client site to another server(Not the application server). The code is just like below:
FileUpload1.SaveAs(Server.MapPath(#"xx.xx.xx.xx\" + FileUpload1.FileName));
The error occurred after i have deployed the application into the web application server. But when run locally successfully uploaded.
I suspect the File Uploader that run from the application server cannot found the path from client site. It is because the path of the image does not existed in the application server.
There are two question regarding this issue:
1) Is there anyway to resolved this issue.
2) Is there any differences between "FileUpload1.PostedFile.SaveAs()" and FileUpload1.SaveAs()?
Thanks for trying to help me on this.
You should write path as img.Save("c:\\Users\\user\\Desktop\\Barcodes\\1.png", System.Drawing.Imaging.ImageFormat.Png);

Get last modified date of a remote file

I have an app with which at startup it downloads a file from a remote location (through the net) and parses it's contents.
I am trying to speed up the process of startup as the bigger the file gets the slower the app starts.
As a way to speed up the process I thought of getting the last modified date of the file and if it is newer from the file on the user's pc then and only then download it.
I have found many ways to do it online but none of them are in C# (for windows store apps). Does anybody here know of a way of doing this without the need to download the file? If I am to download the file then the process is sped up at all.
My C# code for downloading the file currently is this
const string fileLocation = "link to dropbox";
var uri = new Uri(fileLocation);
var downloader = new BackgroundDownloader();
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("feedlist.txt",CreationCollisionOption.ReplaceExisting);
DownloadOperation download = downloader.CreateDownload(uri, file);
await download.StartAsync();
If it helps the file is stored in dropbox but if any of you guys have a suggestion for another free file hosting service I am open to suggestions
Generally, you can check the file time by sending HEAD request and parsing/looking HTTP header response for a Last-Modified filed. The remote server should support it and DropBox does not support this feature for direct links (only via API). But DropBox have another feature, the headers have the etag field. You should store it and check in the next request. If it changed - the file has been changed too. You can use this tool to check the remote file headers.

Download and save aspx page

I saved aspx page as html it worked in my local machine but after published on the server its showing an error that "the access to the path is denied"... I tried giving access permission then also it doesn't work.. can anyone help with it? or else is there any other way to save the page in C# asp.net?...
string url=HttpContext.Current.Request.Url.AbsoluteUri;
string sHtml="";
HttpWebRequest request;
HttpWebResponse response=null;
Stream stream=null;
request=HttpWebRequest)WebRequest.Create(url);
response=(HttpWebResponse)request.GetResponse();
stream=response.GetResponseStream();
StreamReader sr=new StreamReader(stream,System.Text.Encoding.Default);
sHtml=sr.ReadToEnd();
string path=Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string textfilename=TextBox1.Text;
string getpath=path+"\\"+textfilename+".html";
File.WriteAllText(getpath,sHtml);
if(stream!=null)stream.Close();
if(response!=null)response.Close();
Thanks..
If you need to save a file use this to get the application path
Server.MapPath(#"filename.txt");
Try this because when you only write the filename at an web server you are trying to access to a Microsoft.Net folder.
yes make sure the folder you write to has the appropriate privileges. IIS 5 uses ASPNET account, IIS6 uses network service. Just give read/write to the proper account. Is this your dev environment, or a prod environment?
Also, make sure it's pointing to a folder; desktop folder for ASPNET account probably won't exist since ASPNET account isn't a user with a users folder.
I had a similar problem when trying to deploy CSS from a ZIP downloaded from the web. Try right-clicking on the aspx file from windows explorer and checking the file properties. One of the tabs may indicate that the file has been "blocked". If so, there will be a button there to unblock it.

Categories