So I'm tasked to build a file upload for our application, which is using Visual WebGUI and therefore mostly looks like WinForms codewise.
The problem is, I don't have any clues as to where to start. I tried looking through our Download class, but it just takes a file and puts it into the response.
I tried google, but there's nothing on uploading something.
I don't understand enough of how websites work to even ask myself or google the right question. I have no Idea how a website tells the browser to get a file. And if I find out how that works, I still need to somehow get VWG to do that. I can't directly interact with the browser (except when I write javascript, but I'm not sure I can get a response from js).
Ideas and clues to where to start would be great too, I just need somewhere to start.
Let me know if you need any more information or clarification, as I'm not sure which kind of information you need for this.
Visual WebGUI has a built in Upload mechanism, called the UploadControl.
Since you're using VWG, you should check out the Companion Kit which is one of few remaining resources out there for Visual Web Gui. It gives an example of the upload control. It also gives example code, which you can download.
In short, what happens is that VWG will handle the JS components of getting the file. You don't have to worry about JavaScript, that's the point of VWG. In C#, you'll code the UploadControl, and what you "get" is the information about the file like Name, Size, MIME type, etc. Refer to the companion kit for info on this.
Steps:
1) Add the UploadControl to a form
this.mobjUploadControl = new Gizmox.WebGUI.Forms.UploadControl();
2) Wire up the UploadControl
this.mobjUploadControl.UploadFileCompleted += new Gizmox.WebGUI.Forms.UploadFileCompletedHandler(this.mobjUploadControl_UploadFileCompleted);
3) Handle the actual upload.
private void mobjUploadControl_UploadFileCompleted(object sender, UploadCompletedEventArgs e)
{
UploadFileResult uploadedFile = e.Result;
// binary data for file, can be used to store to filesystem, db, etc
byte[] fileData = File.ReadAllBytes(uploadedFile.TempFileFullName);
// filename of what was uploaded
string fileName = uploadedFile.Name;
}
Related
I am trying to build my first ever API and I want it to read some text from a .txt file.
I wrote the code originally to have the text be stored in memory and then remove it after the HTTP Get request. I had it working properly when I would run it in Visual Studio, so I decided to deploy it to Azure. I would then make the HTTP request to add more text into the memory and then I would essentially request it back, however I wouldn't get the text I wanted back. Instead I would get my error message saying that there is nothing in the list which holds the text I want.
I then decided to have it write the text to a .txt file then receive it from that. Once again this worked on my side, but once I published the code to Azure and send a request, I get a 500 Internal Server Error.
At the end of this long story is my question since I can't seem to find any details about .txt files on an Azure Web server.
Is it possible to have my C# class's in my Models folder of my API Web app read a .txt file on an Azure server?
Is it possible to have my C# class's in my Models folder of my API Web app read a .txt file on an Azure server?
The short answer: yes.
The slightly longer answer: yes, however...
As posted in the comments reading and writing information to and from a file in a web application can go bad really fast. Think about two users trying to write at the same time, one user reading at the moment another one is writing and so on.
Now I can imagine the only thing you want to do right now is test to see if it works, so multiple users might not be on top of mind. But even a proof of concept deserves the correct approach, since you might learn something the wrong way otherwise.
Have a look at storing your information in a data store inside Azure, there are quite a few options. For this just to work, it's probably best to use something that's not too hard to set up like Table Storage. If you run into any issues trying to get this to work, open up a new question and we'll be happy to help.
500 Internal Server Error, these is general error in server side. I reproduce same problem and its working fine by using following steps.
After deploy on Azure its show 500 error.
you find actual error to enable Application Insights and go to Failures tab. You can see actual error why occurred.
Click on Error
See Error and File location.
Check File location, if file not there location then create a file on that location. Go to advance tool
Click to go link.
Select Cmd from Debug console dropdown. and click on Site->wwwroot
Create a txt file
Output : Now its working.
I'm trying to retrieve a file from the Process.Start()-Method.
Following scenario is given:
I obtain a link from a third party program. This link can be a UNC-path, direct link to PDF/JPG/TIF-files, such as "www.certainServer.de/test.pdf", as well as link to programs on the server, which return a special file type, such as "www.certainServer.de/test.aspx".
I open the file like this
Process.Start(_path)
If the link is like "www.certainServer.de/test.aspx" the returned file is automatically downloaded to the deposited download folder.
Is there a opportunity to retrieve the downloaded file or the path to the downloaded file?
The returned Process-object from the Process.Start()-Method doesn't seem to be helpful.
Process.Start does not necessarily download a file. It simply starts a process. You just as easily could start Notepad, which has no side effects (except, of course, what you do with notepad once it's started). If the process you start (in your case, calling a web page) has external effects, the process engine knows nothing about it.
It sounds like you know where the file is supposed to be deposited, so you could use something like a FileSystemWatcher to be alerted when a new file is added (which doesn't necessarily mean it came from your process, though) or get a list of files before and after the process is run.
But there's nothing inherent to System.Process to definitively know what that process did.
Another option might be to call the URL from your code (using WebClient or something similar) and capturing the result (which might be a file, or just a web page, depending on the URL). It's not as general as starting a process and letting the default browser handle the download, but it would capture the results more definitively.
What I am trying to do is:
I have a Asp Mvc website. In it I need to create a function that does the following:
converts a .dwg (AutoCad) file to a .pdf file
converts a .dwg file to a .dwf file
I started with the, what I tought at the time, easier task to have the .dwg to a .pdf. After some research I found out that a way to do that (without buying a 3rd party license) is to install TrueView on the server and using it (or actually a AcCtrl.dll) to convert the file. Well, I did so. I installed the True View program and added a reference to AcCtrl Component (ACCTRLLib). Then I added a reference to the Dll inside the class file I am working on:
using ACCTRLLib;
So far so good. After that I followed the instructions on this post: PDF conversion using dwg true viewer in VB6
First, this is my code:
public static void ConvertFile()
{
IAcCtrl contrl = new AcCtrl();
contrl.PutSourcePath(#"D:\MMA\Autocat\File1.dwg");
string[] pdfPath = new string[1] { #"D:\MMA\Autocat\File1.dwg" };
contrl.SilentPublish(pdfPath);
}
Then, according to the post, I went to see if there is a registry with the specified path. The path that I have as a registry is the following:
HKEY_CURRENT_USER\Software\Autodesk\DWG TrueView\R13\DWGVIEWR-E001:409\Profiles\<<\Unnamed Profile>>\Dialogs\AcPublishDlg
So, I created a 'String Value' in it with ValueName: Location and ValueData: D:\MMA\Autocat\Testing
Alright. So, thats it. After all that I ran the application and called the function. The debugger goes through the code and everything executes (or at least looks like so) but nothing happens. I don't get a file in the D:\MMA\Autocat\Testing folder. I get no exception, no warning nothing. It just executes and nothing happens.
So what else did I tried. Some of those things might be a little naive or silly to try but nevertheless I did as I happen to be a little desperate.
I tried everything in a console application. I wasnt completely sure that this method is suitable for ASP MVC so I tried the same code with a console application unfortunatelly to the same result.
I added a file name inside the location string value. I changed the Location ValueData from 'D:\MMA\Autocat\Testing' to 'D:\MMA\Autocat\Testing\testFile.pdf' as I noticed that nowhere in the whole process a file name is asked for the converted file.
Following my thought from the previous conclusion I tried to supply the path to the 'result' file to the SilentPublish function.
string[] pdfPath = new string[1] { #"D:\MMA\Autocat\Testing\testFile.pdf" };
contrl.SilentPublish(pdfPath);
Again to no avail. So, my question, or rather questions are:
Is it possible to do it this way and if it is what am I doing wrong?
If its not than can you suggest a way?
Also if a .dwg to .dwf conversion is possible (with the same or different method I am all ears)
Thank you very much
True View does not expose the Autodesk.AutoCAD.PlottingServices namespace. You're going to need either a licensed copy of AutoCAD, RealDWG, or another third party API.
I'm not sure if you are still having this issue, but you should be able to do this with the Autodesk Forge API. Calls can be made from any language with a simple HTTP call. You will have to first convert to SVF and then to DXF and PDF from there.
I feel like I've gone in a thousand circles on this and it should be much simpler than it is, but basically I have this simple resume submission page in asp.net using C#. The files are on the server in a folder but it seems every solution I find just does nothing at all when I try to execute it.
Here's some examples of some of the things I've tried:
string folder = "~/App_Data/Resumes/" + Session["ResumeName"].ToString();
string folder2 = Server.MapPath("~/App_Data/Resumes/" + Session["ResumeName"].ToString());
System.Web.VirtualPathUtility.ToAbsolute(folder);
System.Diagnostics.Process.Start(folder2);
I'd never imagined something as simple as opening a document from a server would be so difficult. Is it not possible to just simply have a link to a document and have it opened when the user clicks it? That's all I want to accomplish. Thank you reading my through my frustration.
To clarify, System.Diagnostics.Process.Start(folder2); works locally, but doesn't work on the web server. I want this to work on the web server so that's why that one is out. I've tried to make it possible for the web server to open that file but I don't think I know enough about IIS to make it happen.
App_Data is a protected folder in ASP.NET. IIS will not serve anything from that folder directly to the client-- you will need to build a handler that serves the document directly.
Here are a few samples, though they aren't representative of everything you need to do. Others can feel free to add additional resources. Your handler would have to open the file and write it to the output stream:
Using a c# handler to serve up wav files cuts audio short (only a couple of seconds)
ASP.net cache ASHX file server-side
Don't use folders like App_Data to have your downloadable resources .
There is a similar question on stackoverflow which will give you a exact step by step answer - ASP.NET file download from server
From the title of your question, If I understand correctly you want to open a .doc or .pdf on a link or button click. This will open the respective document on the client.
<a id="lnkResume" href="#" runat="server" target="_blank">Download Resume</a>
And you can set the dynamic resume name from the code like below
string fileName = Session["ResumeName"].ToString();
lnkResume.HRef = Server.MapPath("~/App_Data/Resumes/" + fileName);
EDIT Solution Found: See my post below.
We are writing a library that reads in a TIF file from a scanner. Basically, its a scantron. We are examining the form and reading values from it.
Currently we have a windows test app, and we give it a filepath as a string ("c:\testing\image.tif"). It loads up the tif, reads the document correctly and parses the values.
We also have an ASP.NET web application. We have a test page that does exactly what the windows app does, we hand it an identical string, and i calls the same function on the same class from the same library. It however does NOT read the form correctly. We have verified that it does it fact load up the tif file, and it is actually filled with data (pixels we expect to be white/black are white/black when we examine the Bitmap obect in the immediate window of Visual Studio).
The specific problem is in a library called DataMatrix we use to scan a bar-code off the document. This function is supposed to return a List<string>, each of which is a barcode the library found on the document. In the windows app, this function (DataMatrixDecoder.DecodeBarcode(bitmap)) correctly returns with a Count=1. When using the asp.net app, this returns with Count=0.
Because its the exact same image file, I cannot imagine the problem is in DataMatrix. I can only assume its something with ASP.NET or something.
This isn't even my project, but another guy and I are helping our coworker figure this out, and we are just pulling our hair out. All signs indicate that ASP.NET is correctly loading and handing the image off disk to the "processor" class (which is a class library that uses the DataMatrix stuff, we are not doing ANY code in ASP.NET except for opening/handing the file to the function.).
Does anyone have any ideas as to what it might be, or different things we can check?
I'm not even sure what kind of information to give so I tried to say it all, if you have any questions please ask I'd be more than happy to elaborate on anything. Thanks.
edit:
this is the code on the ascx.cs code-behind, in a button-click event:
if (formReader.ReadTIFF(#"c:\testing\image.tif"))
{
messages.Controls.Add(HtmlHelper.DivSuccess("Read successful."));
}
The formReader class then open the file with a FileStream, and uses that to create a Bitmap. The ASP.NET application is not actually opening the file at all (we were uploading it through a FormUpload control, but after experiencing problems we dummied it down to this). This is the most perplexing thing, that it works in the windows app but not from this web site. ASP.NET has full permissions on that folder to do whatever it wants. It can open the image fine, and the bitmap it creates from the FileStream is the actual image.
edit: Also, the ReadTIFF function right now copies the FileStream into a MemoryStream, ensuring its a not a problem streaming from disk (the entire file is in memory).
How are you passing the filepath to the web application?
It is possible that the function which Decodes might be swallowing some exception.
Use reflector to examine the library (if you have not written it).
I agree. It seems your problem is most probably related to User rights on the directory where you're trying to access the files from. Try giving your Web users the Full access rights on the source directory.
EDIT
Solution Found: The problem was that the open file dialog was changing the CurrentWorkingDirectory. The reason the website never worked, was because the Environment.CurrentDirectory was set incorrectly. When I manually set the CurrentDirectory to the websites' bin folder, parsing works correctly.
Small update. Using the Windows App, and selecting the file via OpenFileDialog, will cause the barcode decoder to fail. Technically, I am using the exact same string to hand to the parser ("c:\testing\image.tif"), yet when I use the OpenFileDialog to get the string, the decoder fails. Is there a clue in this?
update: In fact, even if I don't use the string the OpenFileDialog gives me, if I just open the file dialog at all, it will fail. I don't get this. It's something simple. I need to debug the C++ DataMatrix library, really.