[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Upload file

Posted on 2013-06-07
13
Medium Priority
?
558 Views
Last Modified: 2013-06-12
Hi,

How can I modify the code to accept file from file upload control instead of hard coding as follows?

if (stlUtils.IsValidated(new string[] { @"c:\myfile.stl", ddlUnit.SelectedValue.ToString() }))

<asp:FileUpload ID="fuStlFile" runat="server" />

Please help.

ayha
0
Comment
Question by:ayha1999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
13 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39231136
if (stlUtils.IsValidated(new string[] { fuStlFile.FileName, ddlUnit.SelectedValue.ToString() }))

Open in new window

0
 
LVL 7

Author Comment

by:ayha1999
ID: 39231141
I tried both fuStlFile.FileName and fuStlFile.PostedFile.FileName but doesn't work.

the first one doesn't give any result, the other one gives an error

The process cannot access the file 'C:\myFile.stl' because it is being used by another process.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39231146
What is your goal? What are you attempting to do with the uploaded file?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 7

Author Comment

by:ayha1999
ID: 39231153
calculating the volume of the file

        public double CalculateVolume2(string unit)
        {
            br = new BinaryReader(File.Open(_filename, FileMode.Open));
            byte[] buffer = new byte[128];

            br.Read(buffer, 0, 80);
...
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1000 total points
ID: 39231172
The filename is more of a convenience for you, the developer, to know what the user had named the file (on their machine). That name doesn't exist on your machine--unless you write that file out to disk, and name it with that same name.

It appears that you are trying to get the bytes of the file. The good new for you is that the FileUpload control already provides you this via the FileBytes property. Simply modify you class a tad to have a new class-level member:

public class YourClass
{
    private byte[] _fileData;
...

Open in new window


...and then assign the file bytes to this new member wherever you are assigning the filename.

e.g.

...

public void SomeMethod()
{
    this._filename = fuStlFile.FileName;
    this._fileData = fuStlFile.FileBytes;
}

...

Open in new window


Then you can use this data within your other method:

public double CalculateVolume2(string unit)
{
    // use this._fileData here...it's already a byte array
    ...

Open in new window

0
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 39231214
@Kaufmed

He is trying to merge the code from here http://www.experts-exchange.com/Programming/Languages/Scripting/Python/Q_28149820.html#a39229038
Into a file upload program.

System takes a .STL file and calculates the volume of the object described in the STL.

What he is looking for is how to take the uploaded file and pass it through to the STL class so it can process it based on the code in the above link.
0
 
LVL 7

Author Comment

by:ayha1999
ID: 39231221
this solution works


            fuStlFile.SaveAs(Server.MapPath("/files/"  + filename));

            if (stlUtils.IsValidated(new string[] {@Server.MapPath("/files/"+ filename), unit }))
            {
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39231835
OK, but I still don't see why you'd write the bytes out to file just to read them back again--unless of course you need a copy of the file for some other reason. Just pass the byte array around.
0
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 39231848
@kaufmed - did I miss the bit where he is writing out to a file?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39232007
Two posts up.
0
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 39232569
I think that is just saving the uploaded file so it can be used by the STL class to calculate the volume of the object in the file ?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39233026
I think that is just saving the uploaded file...
Exactly my point. If you don't need a copy of the file for archival purposes, why write it out to disk at all? If you do need a copy, then the point is moot.
0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 39241443
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question