Open IManDocument in browser - c#

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.

Related

pptm file not downloading on IIS 6.0

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

How to get file path and name to save this file?

I use open XML to export excel file. SpreadsheetDocument.Create requires a file destination.
I want to get this file destination from user similar to a SaveFileDialog in Winforms.
How I get file destination from user? I use Asp.Net 4.0 and OpenXML SDK 2.5 .
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(destination, SpreadsheetDocumentType.Workbook);
For this functionality even if you use open/save dialog, it would show the client locations not the server locations. So here question is, do you want to save that file to the client machine or at the server machine?
If you want to save it to client machine then first save it on the server by any name and location you want and then initiate a download after that. It will automatically prompt download dialog in the client browser and there user would be able to select the location and filename (depending on the client browser settings).
If you want to save it only on server then just before generating the spreadsheet, prompt user for entering the filename (on the page from where the request is generated). If some of your folders are accessible to user then you can also prompt user to select one of the folders, otherwise choose one as per your choice/requirement. Use the filename and the location to generate the spreadsheet.
when a webserver is streaming a file down to the client, you don't have control of the destination folder. All you can do is:
specify the contents type (to aid client in determining how to handle)
specify filename
(I think) tell the client browser to save the file vs. displaying it automatically in the registered application (for example, PDFs usually display in the browser, but setting up the streaming correctly could force Save File dialog instead)
If you need to "cache" the file ion the web server, you export to a server folder that your server process has write permissions to. Then you stream to the client - the client will get the prompt from their browser and save where they want.
Look at Server.MapPath for example - it'll map virtual path to physical on your server. the question of permissions remains.
Depending on your particular case, you may be able to avoid saving to the server, if the export library has a way of returning a byte array or a stream, instead of saving to a file. In that case you just stream the return result to requester.
I am not familiar with the SDK you're using, but quick googling reveals this method of returning the document in a stream:
using (MemoryStream stream = new MemoryStream())
{
using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook, true))
{
... work with the spreadsheetDocument, if needed
... prepare and stream to browser
}
}
Here's one of the references to your SDK I found
Use Environment.SpecialFolder enumerations. If you are looking for my documents then:
var destination = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(destination, SpreadsheetDocumentType.Workbook);

Print to Network (Shared) Printer - Word Interop

I need to print a word document on server side to a network printer. My web page sends the document and file location to the server to open and replace mail merge items and then print the document to a preferred (not default) network printer. Preferred printer name changes when document selected on web page changes
I'm using Word 14.0 object library, Asp.Net MVC 4.0, .Net Framework 4.0, IIS 7 on windows server 2008 R2. On IIS I created an app pool that runs on an specific account Identity (accountName#DomainName). Load user profile set to true to load the network printer connections in to the registry. I allowed the Account to have permissions to run the word COM interop services. I was successful to open the document and replace the mail merge fields and save it as pdf to send the file as attachment to an email.
The word application has the default printer in its ActivePrinter property, so that I could print to default printer as well. But my final goal is to print the word to a preferred network printer before I close the word application and active document.
The following two Methods were causing exceptions if I try to change the ActivePrinter property.
Word.Application wordApp = new Word.Application();
First Method:
wordApp.ActivePrinter = "preferredPrinterName";
Second Method;
object[] oWordDialogParams = { "\\<serverName>\<PrinterName>", true };
string[] argNames = { "Printer", "DoNotSetAsSysDefault" };
object wordBasic = wordApp.WordBasic;
wordBasic.GetType().InvokeMember("FilePrintSetup"
, System.Reflection.BindingFlags.InvokeMethod
, null
, wordBasic
, oWordDialogParams
, null
, null
, argNames);
I found that the Word application object is not loading all the printers installed to the user account. It only loads the default printer. I'm assuming that it was the reason for exceptions when above two methods were attempting to change or add preferred printer to the application object because the printer I'm trying to set was never found in the active printers list.
How do I get all installed shared printers under user profile loaded in to the Word application object?
Using Office interop in a server-scenario (like ASP.NET, Windows Service etc.) is NOT supported by MS - see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
Additionally there have been several security-related changed since Windows Vista which basically make it really hard to do anything "desktop-like" in a Windows Service (IIS/ASP.NET is just a special case of Windows Service in this regard).
Another point is "printing" from a server-scenario is likely to cause problems since IIS is a (special) Windows Service... Windows Service usually don't have a "full/real" desktop which in turn is needed for printing robustly...
I don't think that there an easy solution for your scenario...
I would break it down to different components:
Word document handling (for example with Aspose.Words)
Create a PDF from the resulting Word file (for example with Aspose.Words)
Implement a HotFolder on the target network printer
Copy the PDF over to that HotFolder for printing
This would be a robust and supported option for your scenario...

Store DataSet on Sharepoint: ReadXml fails while WriteXml works flawlessly

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

TransmitFile security issue in IE and word

I'm trying to transfer a file (word document) from my server to the client
I'm using this :
Response.TransmitFile(path);
Response.End();
In IE when I click open of the download popup, everything is ok and word open with my document.
The problem is when I click the save button in word, it pop me a security/connection popup. I have to give a username/password for mysite.com
That is normal behaviour since Word handles files opened via browser differently - it tries to verify whether they are "WebDAV-accessible" and uses some MS-specific extensions in doing so... that in turn doesn't use your current browser session but tries/needs to establish a new which in turn leads to Word askting you for credentials.
IF you want to just download it locally you could by using a content-disposition header - this way Word sees it as a local file and tries to save it locally upon "Word save button press".
IF you really want it to be saved back to your site it gets a bit tricky... although as you are running on IIS you might be able to implement something in combination with the IIS-built-in WebDAV functionality...
EDIT - as per comments:
For how to use content-disposition http header see for example http://www.jtricks.com/bits/content_disposition.html

Categories